🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
Guides / Search analytics / Concepts

Query aggregation and processing

To ensure relevant analytics data, search queries are aggregated in the search analytics.

For example, if a user types “beatles”:

The search engine runs seven search queries: “b”, “be”, “bea”, “beat”, “beatl”, beatle”, and “beatles”.

The analytics engine counts only the last query, “beatles”.

Algolia aggregates search queries based on:

  • Edit distance
  • Timestamp (queries within 30 s are aggregated)
  • User ID

By default, the user ID is the user’s IP address. For more accurate analytics, explicitly set a user token

If you make search requests from your backend, the user ID for all searches would be your server’s IP address, which leads to inaccurate analytics. To obtain accurate analytics, you must provide unique user IDs.

To provide unique user IDs, select one of these options:

Forward user IP addresses

If you make search requests from your backend servers, and you don’t want to explicitly set user tokens, you can add the X-Forwarded-For header to forward your users’ IP addresses to Algolia.

1
2
3
4
$res = $index->search('', [
    // Replace `XX.XXX.XXX.XXXX` with your user's IP address
    'X-Forwarded-For' => 'XX.XXX.XXX.XXX',
]);
Did you find this page helpful?