Retriving _rankingInfo in .Net

Hi,

I’m trying to retrieve ranking information from a search response.
The documentation states that a _rankingInfo object is added to the JSON response when GetRankingInfo is set to true.
However, since I’m using .Net, I’m not directly retriving the JSON, but get a SearchResponse object back.
SearchResponse does not contain an object that contains ranking information.

So, how do I access this ?

Hi @LifeIsGood and welcome to the forum. Great user name. :slight_smile:

To confirm, are you able to set .GetRankingInfo(true) when making a query using the CSharp client? If you do that like so:

index.search(
  new Query("query")
    .GetRankingInfo(true)
);  

you should be able to get a response object back that includes a _rankingInfo key with the ranking information. If that’s not the case, would you mind sending us a message at support@algolia.com with your appID / index name / sample script and Algolia support access so we can try to repro?

Thanks in advance!

Hi @maria.schreiber and thanks!
Yes, I’m able to set GetRankingInfo. Which I’m doing like so:

var task = index.SearchAsync<DataType>(new AlgoliaQuery(query) { GetRankingInfo = true });

I’m not sure if I get a response object back. That might be the case, I’m just not sure where to find this response object.
SearchAsync() returns a SearchResponse object, which only contains a list of hits. I’m not sure where I would find a response object in there. It seems to be lacking alltogether in the C# client.

Edit:
Apparently, you’re supposed to add a _rankingInfo object to your DataType that you’re querying for, which is then being filled if GetRankingInfo is true.
This isn’t mentioned anywhere though. I’d highly suggest to mention this specifically in the documentation of the C# client.

So say you’re querying for a Business, which might look like this

public class Business
{
    public string BusinessName { get; set; }
    public int ZipCode { get; set; }
    public string ObjectID { get; set; }
}

you’re supposed to add a _rankingInfo object like

public class Business
{
    public string BusinessName { get; set; }
    public int ZipCode { get; set; }
    public string ObjectID { get; set; }

    public object _rankingInfo { get; set; }
}

where _rankingInfo is probably supposed to be of a more specific type than object (I’ll have a look at the JSON object & recreate that as a C# object)

Edit 2:
Yeah, this works.
Here’s what I ended up with

public class RankingInfo
{
    public int NbTypos { get; set; }
    public int FirstMatchedWord { get; set; }
    public int ProximityDistance { get; set; }
    public int UserScore { get; set; }
    public int GeoDistance { get; set; }
    public int GeoPrecision { get; set; }
    public int NbExactWords { get; set; }
    public int Words { get; set; }
    public int Filters { get; set; }

    public MatchedGeoLocation MatchedGeoLocation { get; set; }
}

public class MatchedGeoLocation
{
    public float Lat { get; set; }
    public float Lng { get; set; }
    public int Distance { get; set; }
}
1 Like

hey @LifeIsGood,
Glad it works in the end. Do you have any other questions? :relaxed:

Thanks for letting us know what worked for you @LifeIsGood! We’ll be sure to pass this feedback on to our documentation team.