Rank by attribute

Good morning, hope you are all well,

I am changing this page to use Algolia search;

It has a list and a map.

The user enters a keyword and it searches across the name and address attributes.

But I also want to take into account the location_region which can be one of; US, IE, GL.

I want the relevant results based on location_region to rank higher in the results. I don’t want to facet it and exclude IE or GL or US results.

How do I pass in the user’s location_region to help rank the results?

Thank you.

1 Like


We do have a feature of optionalFilters that lets you give more weight to items that match a specific filter. Unfortunately, it’s an Enterprise-only feature.

In your specific example what could be easier would be to leverage our geo-location feature. If you can add to each record a _geo.lat and _geo.lng attributes, we will then be able to sort them by relative proximity to your user. It will be based on the user IP, or you can specify your own coordinated.

Otherwise you might be able to achieve a similar result by doing two queries and merging the results. The first query would have a filter selecting only the items in the regions you’re interested in, and the second one would do the opposite (exclude results from the interesting region). By concatenating both results you will have the results from the main region first. Note that doing so will break the pagination, though.

1 Like

Thanks for the reply, Tim. optionalFilters does seem like what we need.

Supplying our own coordinate matched to the EN, GL, or IE region for _geo.lat and _geo.lng could work though, thanks for that.