instantsearch icon indicating copy to clipboard operation
instantsearch copied to clipboard

Merge props given both in Configure and other widgets

Open zackify opened this issue 7 years ago • 14 comments

Bug: What is the current behavior? Adding a facetFilter with Configure works. Apply a filter on a Refinement list, and it is removed.

Bug: What is the expected behavior? To merge refinements and add facetFilters from configure

zackify avatar Dec 15 '17 02:12 zackify

Hi @zackify, could you try with the filters attribute instead of facetFilters?

https://www.algolia.com/doc/api-reference/api-parameters/filters/#facet-filters

samouss avatar Dec 15 '17 08:12 samouss

Awesome thanks, that worked

zackify avatar Dec 15 '17 16:12 zackify

We should probably merge the values though, would be less surprising?

Haroenv avatar Dec 15 '17 17:12 Haroenv

I would think so :D

zackify avatar Dec 15 '17 19:12 zackify

Configure should probably take precedence over the other ones.

Haroenv avatar Dec 15 '17 19:12 Haroenv

This is causing some issues for me. I know this is an old issue, but I'm not seeing any updates for this. We were previously getting around this by using filters on Configure instead of facetFilters, but due to a change in requirements that's not an option anymore. Would anyone happen to have an update, or some advice for getting around this?

colepeters avatar Mar 23 '21 18:03 colepeters

Which change made it impossible to use filters? They should be functionally equal. Alternatively you can also use a custom connector using createConnector and fill in getSearchParameters, which will get merged with the other parameters as expected.

Haroenv avatar Mar 24 '21 16:03 Haroenv

When using filters, we were experiencing missing facet options from our index that we needed to see — specifically, facet options which would return 0 results, even though those our attributes for faceting are not set to filterOnly.

I'm thinking using filters fails to return those 0-result facet options because the filtered results the search is operating on don't contain any of those options. What we were hoping to do was to preserve all possible facet options for an index, by using facetFilters to avoid those options getting omitted. But admittedly I'm still getting up to speed on some of these topics, so I could just be way off on all of this. 😅

Either way, is there any work going on to merge these props?

colepeters avatar Mar 24 '21 16:03 colepeters

for the time being, we only received this request once four years ago, so didn't look into how it would work to merge the parameters. I think for advanced use cases like you're describing, it will be best to reference what we do ourselves in the eg. refinement list connector and edit that for your use case, rather than using configure.

Haroenv avatar Mar 25 '21 11:03 Haroenv

Understood. Thanks @Haroenv!

colepeters avatar Mar 25 '21 16:03 colepeters

I've just hit this issue too. Is there any good example of using connectWithQuery but without needing to wrap a component?

We manage the state somewhere else, which comes in via a context/hook and then "translate" it into instantsearch language as an argument on <Configure> like this:

        <Configure
          facetFilters={
            buildFilterBy(filterBy, "instantsearch")
          }
        />

I'm struggling to figure out how this would work with connectWithQuery, any thoughts?

carlreid avatar Mar 25 '22 08:03 carlreid

@carlreid, do you have a complete code sample somewhere? If you are managing the state manually, you could maybe look into virtual widgets or applying the refinement via a connector's refine function. Otherwise you can always use the filters key in configure, that is meant for "non-widget filters"

Haroenv avatar Mar 25 '22 09:03 Haroenv

@Haroenv Nothing I could share immediately without spending some time pulling out components into a small test project.

I'll do some reading up on the virtual widgets, though had already struggled with trying to call the refine function also. I'm having similar problems with filters as others have described above, but again, can try tinker some more to see if I can get something working.

carlreid avatar Mar 25 '22 10:03 carlreid

I understand, but to understand where you are stuck, we'll really need a code sample, sorry!

Haroenv avatar Mar 25 '22 12:03 Haroenv

In the end this doesn't have a clear path and makes configure significantly harder. I recommend to see it as a "can be overridden by other widgets" state, and to use a parameter (like filters) which isn't used by another widget on the page.

Haroenv avatar Aug 09 '24 07:08 Haroenv