C# driver and scoreDetails

Hi @sboulema - Welcome to the community :wave:

I have the following code snippet which was run in my test environment (using C# driver version 2.19.0):

static void Main(string[] args)
        {
            var uri = "<REDACTED>";
            var mongoURL = new MongoUrl(uri);
            var client = new MongoClient(mongoURL);
            var database = client.GetDatabase("lamp");            
            var collection = database.GetCollection<BsonDocument>("collection");

          	var pipeline = new BsonDocument[]
            {
                new BsonDocument("$search", 
                new BsonDocument
                    {
                        { "index", "default" }, 
                        { "autocomplete", 
                new BsonDocument
                        {
                            { "query", "lamp" }, 
                            { "path", "name" }
                        } }, 
                        { "scoreDetails", true }
                    }),
                new BsonDocument("$project", 
                new BsonDocument
                    {
                        { "_id", 0 }, 
                        { "name", 1 }, 
                        { "scoreDetails", 
                new BsonDocument("$meta", "searchScoreDetails") }
                    })
            };
            
           	var result = collection.Aggregate<BsonDocument>(pipeline).ToList();

            foreach (var document in result)
            {
                Console.WriteLine(document);
            }

            Console.WriteLine("Finished!");
        }

Which provides the following output (cut short for brevity but you can see the scoreDetails field in the output):

{ "name" : "floor lamp", "scoreDetails" : { "value" : 2.0917689800262451, "description" : "sum of:", "details" : [{ "value" : 1.0077003240585327, "description" : "$type:autocomplete/name:lamp [BM25Similarity], result of:" ...

Hoping my above example helps but regarding this question, do you have an example of how you’re performing the search with "returnStoredSource" so I can assist better here.

Look forward to hearing from you.

Regards,
Jason

1 Like