Combined facet active item incorrect

Created on 25 May 2022, about 2 years ago
Updated 5 June 2024, 23 days ago

Problem/Motivation

When using the Combine Facets processor the active state isn't correctly determined for the Result which means that the URL gets created incorrectly as the filter parameter is added a second time instead of being removed.

Steps to reproduce

  • Create search API view for search
  • Create a facet (links)
  • Create a second facet (links) and select the Combine Facet (union) processor.
  • Place facet block for combined facet on search page.
  • Filter by both facets
  • Remove the facet that was added via combining
  • Filter not removed and duplicate filter in URL

Proposed resolution

I followed this through but it was taking too much time to get to a fix and I had to move on. I think the problem lies in the setResults() method on the Facet Entity. It seems like the facet doesn't always have the raw values from the combined facet. On my particular installation this ran about five times for the combined facet and only the last one correctly set the active states but that didn't seem to be the one used for the actual facet build.

As a workaround I fixed it by subscribing to the QueryStringCreated event and analysing the facet and active states provided.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom very_random_man

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 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:oak

    Doing 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?

Production build 0.69.0 2024