> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# getRankingInfo

> Add details about ranking to each result

export const Setting = ({type, default: defaultValue, defaultNote, scope, min, max, formerly}) => {
  const renderedDefault = defaultValue === '' ? '""' : defaultValue;
  const renderedNote = defaultNote ? `(${defaultNote})` : '';
  return <ul>
      <li><strong>Type:</strong> <code>{type}</code></li>
      <li><strong>Default:</strong> <code>{renderedDefault}</code>{renderedNote}</li>
      {min && <li><strong>Min:</strong> <code>{min}</code></li>}
      {max && <li><strong>Max:</strong> <code>{max}</code></li>}
      <li><strong>Scope:</strong> <a href="/doc/api-reference/api-parameters"><code>{scope}</code></a></li>
      {formerly && <li>
          <strong>Deprecated name:</strong> <code>{formerly}</code>
        </li>}
    </ul>;
};

<Setting type="boolean" default="false" scope="search" />

The `getRankingInfo` parameter adds a `_rankingInfo` object to each result (hit) in the search response.
This object contains detailed metadata about how Algolia ranked the result, including scores from ranking criteria.

## `_rankingInfo`

Object with details about ranking of each result.

<Expandable>
  <ResponseField name="_rankingInfo.nbTypos" type="integer">
    Number of typos for this match.
  </ResponseField>

  <ResponseField name="_rankingInfo.firstMatchedWord" type="integer">
    Encodes both the attribute index (position in [`searchableAttributes`](/doc/api-reference/api-parameters/searchableAttributes)) and the word position.
    Divide the number by 1,000 to get the attribute index; the remainder gives the word position.
    Used only for attributes set to `"ordered"` in `searchableAttributes`.

    For example, if `firstMatchedWord` is 2,001: the best-matching attribute is the second attribute in the list,
    and the first matched word is the second word within that attribute (both 0-based).

    For more details, see [Understanding word position](/doc/guides/managing-results/must-do/searchable-attributes/how-to/configuring-searchable-attributes-the-right-way#word-position).
  </ResponseField>

  <ResponseField name="_rankingInfo.proximityDistance" type="integer">
    Sum of distances between matched query words.
  </ResponseField>

  <ResponseField name="_rankingInfo.userScore" type="integer">
    Internal custom ranking score for the record.
    (Reserved for internal use by Algolia).
  </ResponseField>

  <ResponseField name="_rankingInfo.nbExactWords" type="integer">
    Number of words that matched exactly.
    If [`alternativesAsExact`](/doc/api-reference/api-parameters/alternativesAsExact) is not empty,
    it includes matches with plurals or synonyms.
  </ResponseField>

  <ResponseField name="_rankingInfo.words" type="integer">
    Number of matched query words, including prefix and typo-tolerant matches.
  </ResponseField>

  <ResponseField name="_rankingInfo.filters" type="integer">
    Filter scores.
    For more information, see [Optional filters' scoring](/doc/guides/managing-results/rules/merchandising-and-promoting/in-depth/optional-filters#filter-scoring)
  </ResponseField>

  <ResponseField name="_rankingInfo.promoted" type="boolean">
    True if the result was promoted by a rule.
    Absent otherwise.
  </ResponseField>

  <ResponseField name="_rankingInfo.geoDistance" type="integer">
    Distance from the query's location to the matched record's location, divided by the precision.
  </ResponseField>

  <ResponseField name="_rankingInfo.geoPrecision" type="integer">
    Precision for calculating distances, in meters.
    All distances are multiples of this setting.
  </ResponseField>

  <ResponseField name="_rankingInfo.matchedGeoLocation" type="object">
    Details about the matched geographic point, including coordinates and distance.

    `lat` and `lng` are Algolia's internal values, not the original `_geoloc` on the record. Returned values may show fewer decimals than the values you indexed. For background, see [Geographical ranking precision](/doc/guides/managing-results/refine-results/geolocation/in-depth/geo-ranking-precision).

    <Expandable>
      <ResponseField name="matchedGeoLocation.lat" type="number">
        Latitude of the matched point.
      </ResponseField>

      <ResponseField name="matchedGeoLocation.lng" type="number">
        Longitude of the matched point.
      </ResponseField>

      <ResponseField name="matchedGeoLocation.distance" type="integer">
        Distance from the search center to the matched point, in meters.
      </ResponseField>
    </Expandable>
  </ResponseField>

  <ResponseField name="_rankingInfo.personalization" type="object">
    Information about how [Personalization](/doc/guides/personalization/classic-personalization/what-is-personalization) influenced this result (if enabled).
  </ResponseField>

  <ResponseField name="_rankingInfo.serverUsed" type="string">
    Internal name of the server that processed the request.
  </ResponseField>

  <ResponseField name="_rankingInfo.indexUsed" type="string">
    Index name used for the query.
    This may differ in A/B tests.
  </ResponseField>

  <ResponseField name="_rankingInfo.abTestID" type="string">
    ID of the A/B test if applicable.
  </ResponseField>

  <ResponseField name="_rankingInfo.abTestVariantID" type="integer">
    Variant ID (position in the list of variants) used in the A/B test. Starts from 1.
  </ResponseField>

  <ResponseField name="_rankingInfo.parsedQuery" type="string">
    Normalized query string after [stop word removal](/doc/api-reference/api-parameters/removeStopWords)
    and [advanced syntax](/doc/api-reference/api-parameters/advancedSyntax) processing.
  </ResponseField>

  <ResponseField name="_rankingInfo.timeoutCounts" type="boolean">
    True if facet counts were approximated due to a timeout.
  </ResponseField>

  <ResponseField name="_rankingInfo.timeoutHits" type="boolean">
    True if the engine did not retrieve all results due to a timeout.
  </ResponseField>

  <ResponseField name="_rankingInfo.appliedRules" type="list<string>">
    List of [index rule](/doc/guides/managing-results/rules/rules-overview) IDs applied to the query.
  </ResponseField>
</Expandable>

## Example

<AccordionGroup>
  <Accordion title="Current API clients" defaultOpen="true">
    <CodeGroup>
      ```cs C# theme={"system"}
      var response = await client.SearchSingleIndexAsync<Hit>(
        "INDEX_NAME",
        new SearchParams(new SearchParamsObject { Query = "query", GetRankingInfo = true })
      );
      ```

      ```dart Dart theme={"system"}
      final response = await client.searchSingleIndex(
        indexName: "INDEX_NAME",
        searchParams: SearchParamsObject(
          query: "query",
          getRankingInfo: true,
        ),
      );
      ```

      ```go Go theme={"system"}
      response, err := client.SearchSingleIndex(client.NewApiSearchSingleIndexRequest(
        "INDEX_NAME").WithSearchParams(search.SearchParamsObjectAsSearchParams(
        search.NewEmptySearchParamsObject().SetQuery("query").SetGetRankingInfo(true))))
      if err != nil {
        // handle the eventual error
        panic(err)
      }
      ```

      ```java Java theme={"system"}
      SearchResponse response = client.searchSingleIndex(
        "INDEX_NAME",
        new SearchParamsObject().setQuery("query").setGetRankingInfo(true),
        Hit.class
      );
      ```

      ```js JavaScript theme={"system"}
      const response = await client.searchSingleIndex({
        indexName: 'indexName',
        searchParams: { query: 'query', getRankingInfo: true },
      });
      ```

      ```kotlin Kotlin theme={"system"}
      var response =
        client.searchSingleIndex(
          indexName = "INDEX_NAME",
          searchParams = SearchParamsObject(query = "query", getRankingInfo = true),
        )
      ```

      ```php PHP theme={"system"}
      $response = $client->searchSingleIndex(
          'INDEX_NAME',
          ['query' => 'query',
              'getRankingInfo' => true,
          ],
      );
      ```

      ```python Python theme={"system"}
      response = client.search_single_index(
          index_name="INDEX_NAME",
          search_params={
              "query": "query",
              "getRankingInfo": True,
          },
      )
      ```

      ```ruby Ruby theme={"system"}
      response = client.search_single_index(
        "INDEX_NAME",
        Algolia::Search::SearchParamsObject.new(query: "query", get_ranking_info: true)
      )
      ```

      ```scala Scala theme={"system"}
      val response = Await.result(
        client.searchSingleIndex(
          indexName = "INDEX_NAME",
          searchParams = Some(
            SearchParamsObject(
              query = Some("query"),
              getRankingInfo = Some(true)
            )
          )
        ),
        Duration(100, "sec")
      )
      ```

      ```swift Swift theme={"system"}
      let response: SearchResponse<Hit> = try await client.searchSingleIndex(
          indexName: "INDEX_NAME",
          searchParams: SearchSearchParams.searchSearchParamsObject(SearchSearchParamsObject(
              query: "query",
              getRankingInfo: true
          ))
      )
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Legacy API clients">
    <CodeGroup>
      ```cs C# theme={"system"}
      index.search(
        new Query("query")
          .GetRankingInfo(true)
      );
      ```

      ```go Go theme={"system"}
      res, err := index.Search(
      	"query",
      	opt.GetRankingInfo(true),
      )
      ```

      ```java Java theme={"system"}
      index.search(
        new Query("query")
          .setGetRankingInfo(true)
      );
      ```

      ```js JavaScript theme={"system"}
      index
        .search("query", {
          getRankingInfo: true,
        })
        .then(({ hits }) => {
          console.log(hits.map((hit) => hit._rankingInfo));
        });
      ```

      ```kotlin Kotlin theme={"system"}
      val query = query("query") {
          getRankingInfo = true
      }

      index.search(query)
      ```

      ```php PHP theme={"system"}
      $results = $index->search('query', [
        'getRankingInfo' => true
      ]);

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

      ```python Python theme={"system"}
      results = index.search("query", {"getRankingInfo": True})

      # for hit in results['hits']:
      #   print(hit['_rankingInfo'])
      ```

      ```ruby Ruby theme={"system"}
      results = index.search(
        "query",
        {
          getRankingInfo: true
        }
      )

      # results['hits'].each do |hit|
      #   puts hit['_rankingInfo']
      # end
      ```

      ```scala Scala theme={"system"}
      client.execute {
        search into "myIndex" query Query(
          query = Some("query"),
          getRankingInfo = Some(true)
        )
      }
      ```

      ```swift Swift theme={"system"}
      let query = Query("query")
        .set(\.getRankingInfo, to: true)

      index.search(query: query) { result in
        if case .success(let response) = result {
          print("Response: \(response)")
        }
      }
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>
