Hi there. I've been facing a similar issue with the combined facets option. I have 2 taxonomy reference fields (primary and secondary) pointing to the same vocabulary, I created 2 different facets for the primary and secondary field, then in the secondary I chose the combine option and selected the primary field using "Add that facet's results to this facet's results (union).", I also have other facets defined.
The issue comes up when I choose a value from other facet, the search gets filtered correctly and when I look for a specific value in the combined facet I see there are X number of results but when I choose it, the view doesn't show those contents, I think this is because the term listed in the combined facet is only selected in the primary field, the search engine knows about those contents but the query is not properly built when this specific situation happens.
I tried changing the url parameter by directly pointing to the other facet and then I can see the missing results.
The code provided above didn't work for me and I'm not that familiar with the facet events so I'm kinda lost on how to proceed here.
Steps to reproduce
- Create search API view for search
- Create a primary facet (checkboxes) for a taxonomy reference field for example a category list
- Create a secondary facet (checkboxes) for the same taxonomy reference field as the previous item, select the the primary facet and then the "Add that facet's results to this facet's results (union)" option.
- Create a facet (checkboxes) for any other taxonomy reference field let's say a list of brands
- Place facet block for combined category facet on search page.
- Place facet block for brands facet on search page.
- Filter by brand facet
- Check the results on category facet and choose a term that is marked in the not-combined facet
- The result is empty
- Change the URL parameter in the browser with the primary field machine name
- The result is X number of nodes
- π©πͺGermany hexabinaer Berlin, Germany
I ran into the same, trying to combine content type and media type in a single facet. Setting identical URL aliases and ignoring the warning is no workaround btw.
Whatever setting you try, the facet link will be invalid and issue an empty search result.
- π¬π§United Kingdom Hebl
Hey @very_random_man,
Thanks a lot for your code and explanation. Not sure if something has changed in the module code since you did it, but I'm struggling to work out which facet the selected facet item comes from.
All of the facet appears to have the original ID of XXXXX, even if it comes from a YYYYY facet block.
I'm having the same issue as @hexabinaer and @dantesinferno.
- π¬π§United Kingdom very_random_man
Hi. Sorry, I've not worked on the project that I used this fix for for a while so I can't really say if it still applies to a more recent version or not. This fix definitely worked for v2.0.2 but that's about all I can say.
The gist of the fix was to examine the list of filters and ensure that the correct facet ID was applied to each parameter instead of the active facet getting applied to all parameters.
e.g. to change it from something like...
trees:lion, trees:dog, trees:maple, trees:oak
to
animals:lion, animals:dog, trees:maple, trees:oak
- π¬π§United Kingdom Hebl
Thanks for the response @very_random_man, much appreciated.
trees:lion, trees:dog, trees:maple, trees:oak
to
animals:lion, animals:dog, trees:maple, trees:oakDoing this is exactly what I need to do, but within the event subscriber (at least in the version I'm working with), every active facet item is always showing as trees:maple, trees:dog, trees:oak, trees:fish.
On the items where we'd need to change it from trees:dog => animals:dog, there is no identifier in there for me to identify that the facet belongs to animals.
I'll keep digging, thanks again for your help. :)
- π¬π§United Kingdom very_random_man
That's what that loop / switch statement does.
It is iterating over the filter parameters for the combined facet (e.g. trees) and the first case is replacing the incorrect value with a correct value (e.g. trees:lion with animals:lion). My memories of the second case are a bit hazy but looks like it's removing values that are active but not for the combined facet (e.g. animals:lion when we're dealing with the trees facet).
To give a bit more context to my snippet, i only had two single option facets which i'd combined into one so it was perfectly fine for me to directly reference them. If you are dealing with a variable list of things (e.g. a taxonomy, content types, etc) you'd need to wrap that switch in an additional loop to provide the facet values to check against.
Although I can't say if this approach is valid for the current versions. I see there has been a new major version since I'd created this workaround. Maybe that does things differently?