How i can rank my result search in mongodb

Viewed 140

let's say i want to search in document by this name "my jon" and there is names in document like

  1. "my name is jon"
  2. "my is jon"
  3. "jon adam"
  4. "my address"
  5. "jon"

i want to get the rank of result for example 1 has two same words 2 has two same word 3 has one same word 4 has one word 5 has one same word

how i can make it with mongoDB search in C#

2 Answers

See the documentation. Atlas Search ($search) has more ranking options than the text indexes.

@Abdelrhman_Abdo the query would look something like this, though you need to replace the index name with you index name if you create one:

using MongoDB.Bson;
using MongoDB.Driver;
        new BsonArray
    {
        new BsonDocument("$search", 
        new BsonDocument
            {
                { "index", "default" }, 
                { "text", 
        new BsonDocument
                {
                    { "query", "my jon" }, 
                    { "path", "name" }
                } }
            })
    }
Related