typesense / typesense-instantsearch-adapter

A JS adapter library to build rich search interfaces with Typesense and InstantSearch.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with filter_by parameters when using facets

alexgvozden opened this issue · comments

Description

If you set filterBy in the search configuration and use facet filtering with RefinementList, the facet filter overwrites (ignores) filterBy configuration which results in more results

Steps to reproduce

For example if I filter all results by default from config with filterBy
additionalSearchParameters: {
queryBy: "embeddings,title",
vectorQuery: embeddings:([], distance_threshold:0.1),
perPage: 10,
filterBy: "score:>6",
},

and than use facets with

Than request made to server will contain filterBy score, but if I click one of the refinement options facets, than filterBy score is ignore and overwritten by facet filterBy option.

Expected Behavior

Filtering by facet should not ignore and overwrite configured filterBy parameter.

Actual Behavior

Filtering by facet overwrites filter_by parameter in request and only uses facets filter

Metadata

Typesense 0.25.2

Mac OSX

I have fixed this issue and prepare pull request. Please test and merge if that is ok so in next release it's included.
If you foresee some issues, lets say of duplicate keys, than it can be fixed, but overall it would continue to work as it was, as I have included filterBy parameter to be added first.
Thank you

Thank you for the PR, it's an interesting way to solve this.

But, there is actually already a way to setup fixed filter from within Instantsearch: #17 (comment)

Hi, thank you for your answer

If I understand correctly than filter_by is meant to be removed even if it's specified in initial search paramters?

example you provided is about adding a facet helpr, while I have an issue with filter_by property being removed (not for facet but score, which is just a field)

I will try to find if using searchFunction can help for that and what are the function but I see searchFunction is depreceted and onStateChange should be used.

if you can help me understand how to retaing filter_by without changing the code of the library it woudl be great

If I understand correctly than filter_by is meant to be removed even if it's specified in initial search paramters?

That's correct. This is how the InstantSearch library works when used without Typesense. You'd typically use the configure widget to setup default search parameters, and then the other filter widgets will override the default parameters.

example you provided is about adding a facet helpr, while I have an issue with filter_by property being removed (not for facet but score, which is just a field)

It's a facet refinement, which is how Instantsearch calls filtering.

searchFunction is depreceted and onStateChange should be used

I'm not familiar with this deprecation, but if you look at Instantsearch / Algolia forums on how to setup a fixed a fixed filter, you should find the latest way to do this from within Instantsearch.

Thank you!