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?
- First commit to issue fork.
- Merge request !245Issue #3282290: Update active results on combined facets. β (Open) created by richgerdes
- πΊπΈUnited States richgerdes New Jersey, USA
I ran into this issue, it turns out this a compound issue that's the result of a few problems.
The item being added again when removed is the result of the order in which the facets are constructed and the processors execute. If the facets are not ordered correctly, it can result in the combined results not having the active state correctly updated. Just be sure that the facet you are combining is processed first (has a lower weight or is higher in the table then the second). In the example in #1, then issue would exist if the combined configuration existed on the animals facet (including trees). If the trees facet included animals, it should work perfectly. I've added a patch in !244 for β¨ Sort the facets based on the config in the facet summary block Active which sorts the facets when they are loaded in the facet manger. This mean that the facets are processed in a consistent order, and you can configure the facets to fix the mentioned duplicate parameter error.
The second issue I found here is that the facet's active state isn't updated when the results are merged by the combined facets processor. This results in checkboxes being correct, but the combined facet value only showing in the summary if one of the base facets is also enabled. This means that if just `lion` was checked, nothing would appear in the summary. If `lion` and `maple` are checked, both should appear. I've opened !245 to update the active state of the facet with the "combined" configuration during the build phase, so that the active state is reported correctly to the summary block.
You will need to apply both of these patches for the full functionality of the combined facets feature.