Use query data for ranking only

Hello algolia team,
I need to know if i can use query data for ranking only.
I have a problem: in my project i use geo coordinate for search in my index. For exemple, if I search “Paris”, I get the coordinate of Paris and send it to algolia’s API, but I get a bad ranking because a town around Paris can appear before the Paris hits. I use aroundPrecision but it is not enough accurate.
I want to send the query word “Paris” with coordinate for ranking the hits with the word “Paris” first.

If I send a query, the hits without this word disappear as it’s a filter; but can I deactivate this filter and use the query for ranking only ?

Thanks for your feedbacks

Camille

Hi @camille,

Thanks for contacting Algolia! From your description, it sounds like your use-case might be a candidate for our Query Rules.

However, to give you the best advice could you provide a little more precise information.

For example, could you provide an example query you would send, the example record with “Paris” you would want ranked first, and the example recrod without “Paris” that you would want ranked second?

Feel free to include the actual objects with attribute/value.

Look forward to hearing your response. Thank you!

Hi @ajay.david,

Thanks for your feedback. To make it clear, here is what we are trying to do here :

  1. When a User types “Paris”, or “Paris, France” => we want him to get first the results where the word “Paris” or “Paris, France” match “Searchable attributes”.
  2. Once we display the results that matches through the Textual Search, we would like to have the Geo Search work in order to display the closest results AROUND “Paris” or “Paris, France”.
    ==> Then, we would have a results page with a textual Search + Geo in a second step.

Tell me if it’s not clear enough.

Thanks,

Hi @camille,

Thanks for the clarification. As you described, indeed the desire is to have two separate ranking strategies and combine results - first, by text and then second, by geo.

To achieve this you would have to run two separate queries which can hit the same index:

  • Query 1: search the index for “Paris” or “Paris, France” => get hits
  • Query 2: search the index using the _geoloc coordinates of Paris => get hits

Now you’ll have two sets of hits (Query1 and Query 2). On the front-end, you’ll have to filter out of the hits for Query 2 any that already came in Query 1, then combine.

Here are the docs on sending multiple queries in the same call

As an aside, we have a feature called optionalFilters which comes close to achieving what you want - however it applies to a filter on an attribute, not a text query which is why it couldn’t be used in this situation.

Let us know how it goes!