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_connections
is the custom ranking attributecity
andcountry
are set as attributes for faceting, so you can detect whenever a query matches them
Create the rule in the dashboard
This example assumes you’re using the sample dataset.Custom ranking and attributes for faceting
- Go to the Algolia dashboard and select your Algolia application.
- 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_connections
attribute from the drop-down menu. - Click Facets, under Filtering and faceting, then click Add an Attribute and select
country
andcity
from the drop-down menu. - Save your changes.
Rule
Use the dashboard to create a rule that detects matches in facetscity
and country
, and changes the search parameters accordingly.
- Go to the Rules page in the Algolia dashboard.
- Select Create your first rule or New rule.
- In the drop-down menu, click Manual Editor.
-
In the Condition(s) section, keep Query toggled on, click Contains in the drop-down menu, and select country.
{facet:country}
should appear in the input. -
In the Consequence(s) section:
- Click Add consequence and select Add Query Parameter.
- In the input, add the JSON parameters to apply when a user query matches the rule:
{ "aroundLatLngViaIP": false }
- Save your changes.
- Click New Rule and then Manual Editor again.
-
In the Condition(s) section, keep Query toggled on, click Contains in the drop-down menu, and select city.
{facet:city}
should appear in the input. -
In the Consequence(s) section:
- Click Add consequence and select Add Query Parameter.
- In the input field that appears, add the JSON parameters to apply when a user query matches the rule:
{ "aroundLatLngViaIP": false }
- Save your changes.
Create the rule with the API
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 rule
Use thebatch-rules
method to create a rule that detects matches in facets city
and country
, and changes 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_liaisons
.
When not searching for either a city or a country, airports are ranked by distance from the user’s location.
Example dataset
JSON