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:nb_airline_connectionsis the custom ranking attributecityandcountryare set as attributes for faceting, so you can detect whenever a query matches them
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
- Go to the Algolia dashboard and select your Algolia .
- On the left sidebar, select Search.
- Select your Algolia index.
- On the Configuration tab, click Ranking and Sorting.
- Click Add custom ranking attribute and select the
nb_airline_connectionsattribute from the drop-down menu. - Click Facets, under Filtering and faceting, then click Add an Attribute and select
countryandcityfrom the drop-down menu. - Save your changes.
- Visual Editor
- Manual Editor
After configuring custom ranking and attributes for faceting, create a rule for each facet:
- Open Rules and select New rule > Visual Editor.
- Click Set query condition(s) and select contains.
Select Match any value of a facet, choose
country, and click Apply. - In Consequences, expand More consequences and select Apply search parameters.
Enter
{ "aroundLatLngViaIP": false }in Value and click Apply. - Click Review and Publish, then Publish.
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 thebatch-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 setsaroundLatLngViaIP 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