'How do I return the search.score in the results of azure cognitive search in c#

I want to return the score (azure assigns to each result) for each result and display it to the user.
How do I do this?
My application is in C#.

I know that Azure returns "@search.score" with each result, if you look at the json returned by using their web interface.

But I'm using the C# package called Azure.Search.Documents.

See my sample code below. I have a model class called Hotel, that returns the azure result into it.

Do I just add a property called searchScore and it will get filled?

I have tried many things.

Thanks.

Here is a sample of my code:

private static string _searchURL = "searchURL";
private static string _indexName = "indexName";
private static string _queryApiKey = "queryApiKey";
private async Task SearchQuery()
{
        SearchClient searchClientForQueries = new SearchClient(new Uri(_searchURL), _indexName, new AzureKeyCredential(_queryApiKey));

        SearchOptions options = new SearchOptions()
        {
            IncludeTotalCount = true,
            SearchMode = SearchMode.Any,
            QueryType = SearchQueryType.Full
        };

        options.Select.Add("Name");
        options.Select.Add("Address");

        string searchString = "Name:\"The Hotel Name\" AND Address:\"The Address\"";

        SearchResults<Hotel> response = await searchClientForQueries.SearchAsync<Hotel>(searchString, options);
        
        //how do I get the searchScore from the response that azure assigns to each Hotel result?
    }

    public class Hotel
    {
        public string Name { get; set; }
        public string Address { get; set; }
    }


Solution 1:[1]

Since @search.score() retrieves the document's rankings in comparison to other documents which is returned by the query. If your search conditions are met the result is returned using HTTP requests.

POST https://[service name].search.windows.net/indexes/hotels/docs/search?api-version=2020-06-30
{
    "search": "<query string>",
    "scoringStatistics": "global"
}

Here is a sample that you can refer to.

REFERENCES:

  1. Similarity and scoring overview
  2. Search Documents
  3. How to work with search results

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SwethaKandikonda-MT