typesense / typesense-instantsearch-adapter

A JS adapter library to build rich search interfaces with Typesense and InstantSearch.js
MIT License
414 stars 64 forks source link

No mechanism for injecting supplementary, dynamic filters to each query #193

Open zopyx opened 10 months ago

zopyx commented 10 months ago

Feature request:

It is a common use case to add dynamic filters or subqueries in Typesense. For example, in our content management system, we want to limit the search to area=Sales when the user is in the sales folder of the portal. This filter should be applied in all cases for all facets.

Scoped API keys are not a suitable solution as the associated query is always static, and it is not feasible to have a scoped API key for every possible subquery.

The current workaround is to use toggleRefinement for the related field (area in this example) of a subquery with the setting off: Sales. This works for multiple fields, but it only works for simple field=value filters.

It would be a very useful addition if we could specify an arbitrary subquery as part of the InstantSearchAdapter configuration (for example, through additionalSearchParameters).

I understand that this feature request may fall under the scope of Algolia. Is this correct?

Complete discussion: https://typesense-community.slack.com/archives/C01P749MET0/p1705584152093769

jasonbosco commented 10 months ago

@zopyx I just remembered this feature I added a while ago. Could you try using the configure widget with filters set inside: https://github.com/typesense/typesense-instantsearch-adapter#configure

Here's a detailed thread on this topic: https://github.com/typesense/typesense-instantsearch-adapter/issues/17

zopyx commented 10 months ago

@zopyx I just remembered this feature I added a while ago. Could you try using the configure widget with filters set inside: https://github.com/typesense/typesense-instantsearch-adapter#configure

Yes, but this only seems to work as long the facets remain unchanged. This is what was mentioned in the discussion on Slack. As soon facets filters are in the game, this configuration seems to be ignored.

jasonbosco commented 10 months ago

Scratch the Configure widget suggestion. Could you try this instead of static filters: https://github.com/typesense/typesense-instantsearch-adapter/issues/17#issuecomment-828064282

zopyx commented 10 months ago

I tried that here:

https://gist.github.com/zopyx/9897d692571caccba60e49480fc36461#file-gistfile1-txt-L182-L184

But I don't see that this additional filter is being used.

jasonbosco commented 10 months ago

That still uses the Configure widget. Could you use the helper approach like this instead: https://github.com/typesense/typesense-instantsearch-adapter/issues/17#issuecomment-876758570

Specifically this part:

searchFunction(helper) {
        helper.addFacetRefinement('language', 'de').search();
      },