Question about geolocation, multi index search

We have a search page with hits which either have a _geoloc or not. What we want is for results to be filtered by location if the hit has a location, and if the hit doesn’t, then it should still be in the results. I found that this didn’t seem to be possible, so I split our index into two indices: one with locations, one without, and then did only location filtering on one. However maintaining two indices is proving to be problematic, as the results are merged together.

Having multiple indices creates problems such as:

  • merging results according to ranking
  • pagination across indices

I’m looking for a better solution as we build a better search experience, and any advice would be appreciated.

Hi @david1,

Thanks for contacting us. I see what you are trying to do, and we could potentially help you more if you give us a bit more context about what you are trying to achieve (what are you planning to do with the results without geoloc in your app? how do you plan to rank them compared to the ones with geoloc?)

I will tell you some ideas that could be useful to you:

1- The parameter that would help to append results that don’t fit a filter is optionalFilters. Unfortunately it doesn’t work with _geoloc, so that won’t solve your problem directly.

2- You don’t necessarily need to maintain 2 indexes in your case. In fact, you have all of the entries in one index, and then you can query 2 times the same index: one without any filter and the second by checking if hasLocation:true (you can add to your entries an attribute hasLocation which can be true or false).

For your case, there might be no way to get around the 2 queries, but if you tell us more context, then maybe we can find a better way to achieve what you’re trying to do.

Hey Guy,

Thanks for your rapid response. I see option 2 as a way to decrease the code overhead, but not solve the two aforementioned problems I’m facing.

We are a volunteering platform that has both events which are location constrained and vacancies which can be done from anywhere. You can see our algolia search page here: https://www.deedmob.com/discover . Currently results are pooled from 3 indexes, but now that we have ~200 listings we need to add pagination, filtering based on categories and improved ranking strategies.

However this is difficult because we are currently simply adding the results of each of the index queries after eachother. We could theoretically merge the results from the different indices based on some sort of ‘ranking’ attribute of each hit, but pagination doesn’t seem to be feasible without a lot of work.

Alternatively we could swap from using latitudes and longitudes filtering by _geoloc to filter based on country and rank partially according to distance, but I would prefer not to filter by country because people may live near borders, and thus more relevant results would be omitted.

The optimal solution for us would be adding the ability to make _geoloc an optionalFilter.

Thanks for your time and advice,

David

1 Like

Another possible option is to not merge the two result sets, but show them side-by-side as “nearby locations”, “all locations”, does that make sense?

Yeah thanks for the suggestion haroen! That is another possibility, but it involves a UI / UX change that we probably don’t want to make based on technical restrictions

1 Like

Whats the best way to do this using react-instantsearch? <Index> wont do the job due to the index name being the same, right?

Hi @david1,

You can see a documentation on how to do Multi-Indexing in React InstantSearch here, and also you can take a look at an example in order to find a code snippet example (in App.js file)