Skip to main content
You can use rules to enhance the user experience based on what they search for. For example, if you’re building an app to search for airports, Algolia’s geolocation feature helpfully ranks results by proximity. However, the nearest airport isn’t necessarily the best choice. In Paris, a search based on proximity might rank Le Bourget, a small airport for private jets, over large airports like Charles de Gaulle or Orly. As a solution, you could prioritize other factors over proximity. For example, you could rank airports by their number of airline connections. However, if you also set a geolocation parameter like aroundLatLngViaIP, proximity remains the primary factor in determining the order of search results. A better solution is to create a rule so that when users search for a specific city or country, it turns off the aroundLatLngViaIP parameter for that query.

Before you begin

Before creating the rule, ensure that:

Create the rule

Using the dashboard

This example assumes you’re using the sample dataset. You can add these rules from the Algolia dashboard using either the Visual Editor or the Manual Editor.

Custom ranking and attributes for faceting

  1. Go to the Algolia dashboard and select your Algolia .
  2. On the left sidebar, select Search.
  3. Select your Algolia index.
  4. On the Configuration tab, click Ranking and Sorting.
  5. Click Add custom ranking attribute and select the nb_airline_connections attribute from the drop-down menu.
  6. Click Facets, under Filtering and faceting, then click Add an Attribute and select country and city from the drop-down menu.
  7. Save your changes.
After configuring custom ranking and attributes for faceting, create a rule for each facet:
  1. Open Rules and select New rule > Visual Editor.
  2. Click Set query condition(s) and select contains. Select Match any value of a facet, choose country, and click Apply.
  3. In Consequences, expand More consequences and select Apply search parameters. Enter { "aroundLatLngViaIP": false } in Value and click Apply.
  4. Click Review and Publish, then Publish.
Repeat these steps to create the second rule, but choose city instead of country as the facet.

Using the API

To run the code examples on this page, install the latest API client. Before creating the rule, set custom ranking and the attributes for faceting. This example assumes you’re using the sample dataset.

Custom ranking and attributes for faceting

Create the rules

Use the batch-rules method to create rules that detect matches in facets city and country, and change the search parameters accordingly.

Query time

If a user query exactly matches a city or a country in your dataset, the rule sets aroundLatLngViaIP to false overriding any other parameters in the query. For example, if a user searches for “Paris” or “China”, matching airports are ranked by nb_airline_connections. When not searching for either a city or a country, airports are ranked by distance from the user’s location.

Example dataset

JSON

See also

Last modified on September 28, 2026