API Reference / API Parameters / getRankingInfo
Jan. 14, 2019

getRankingInfo

Type: boolean
Engine default: false
Parameter syntax
'getRankingInfo' => true|false

Can be used in these methods:

About this parameter

Retrieve detailed ranking information.

This setting lets you see exactly which ranking criteria played a role in selecting each record.

Impact on the response:

When true, each hit in the response contains an additional _rankingInfo object, which contains the following fields, all at the same level.

  • Textual relevance / Ranking

    • nbTypos (integer): Number of typos encountered when matching the record. Corresponds to the typos ranking criterion in the ranking formula.

    • firstMatchedWord (integer): Position of the most important matched attribute in the attributes to index list. Corresponds to the attribute ranking criterion in the ranking formula.

    • proximityDistance (integer): The sum of the distances between matched words when the query contains more than one word. Corresponds to the proximity criterion in the ranking formula.

    • userScore (integer): Custom ranking for the object, expressed as a single numerical value. This field is internal to Algolia and shouldn’t be relied upon, as it will eventually be removed from the public API.

    • nbExactWords (integer): Number of exactly matched words. If alternativeAsExact is set, it may include plurals and/or synonyms.

    • words (integer): Number of matched words in the query, including prefixes and typos.

    • filters (integer): This field is reserved for advanced usage. It will be zero in most cases.

    • promoted (boolean): Present and set to true if a query rule promoted the hit.

  • Geo search (see how these are used)

    • geoDistance (integer): Distance between the geo location in the search query and the best matching geo location in the record, divided by the geo precision.

    • geoPrecision (integer): Precision used when computed the geo distance, in meters. All distances will be floored to a multiple of this precision.

    • matchedGeoLocation (array): Contains the latitude, longitude, and distance (in meters) from a central axis point.

  • Additional information

    • serverUsed (string): Actual host name of the server that processed the request. (Our DNS supports automatic failover and load balancing, so this may differ from the host name used in the request.)

    • indexUsed (string): Index name used for the query. In case of AB testing, the index returned here is the one that was actually used, either index A (the target) or B (the variant).

    • abTestVariantID (integer): In case of AB testing, returns the ID of the variant used. The variant ID is the position in the array of variants (starting at 1).

    • parsedQuery (string): The query string that will be searched, after normalization. Normalization includes removing stop words (if removeStopWords is enabled), and transforming portions of the query string into phrase queries (see advancedSyntax).

    • timeoutCounts (boolean): Whether a timeout was hit when computing the facet counts. When true, the counts will be interpolated (i.e. approximate). See also exhaustiveFacetsCount.

    • timeoutHits (boolean): Whether a timeout was hit when retrieving the hits. When true, some results may be missing.

Examples

Get ranking info along with search results

1
2
3
4
5
6
7
$results = $index->search('query', [
  'getRankingInfo' => true
]);

//foreach ($results['hits'] as $hit) {
//  var_dump($hit['_rankingInfo']);
//}

Which produces the following results:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
  [...],
  "_rankingInfo": {
      "nbTypos": 0,
      "firstMatchedWord": 0,
      "proximityDistance": 0,
      "userScore": 7,
      "geoDistance": 1600,
      "geoPrecision": 1,
      "nbExactWords": 0,
      "words": 0,
      "filters": 0,
      "matchedGeoLocation": {
          "lat": 37.3688,
          "lng": -122.036,
          "distance": 1600
      }
  }
}

Did you find this page helpful?