Disclaimer, I'm a Drupal newbie, so apologies if this is posted in the wrong place and I appreciate it is probably something I'm doing wrong!

Hi,

I'm using Facet API with search API.
I have facets set up on a taxonomy term for regions and towns. So in the facet list it looks like:

West of country
-City1
-City2
-City3
East of country
-City4
-City5
-City6

I can get this to display exactly as I want, i.e. collapsed until the parent is clicked. I also want the parent categories to remain visible at all times - so have used the OR operator in the Facet display settings.
But, here is the problem:
Say I select "West of country" and the list expands. Next I click the city I want, e.g. "City2".
What happens is I get results from "West of country" AND "City2".

Now, obviously this is how the OR operator is intended to work, but this doesn't really fit the intuitive pattern you'd expect from the hierarchy set up.

Thanks,
Chris

Comments

rupertj’s picture

Version: 7.x-1.3 » 7.x-1.x-dev
Component: Usability » Code
Category: Support request » Bug report
Status: Active » Needs review
StatusFileSize
new1.82 KB

To expand on what Chris said, the issue here is that the 2nd level links onwards in a hierarchical facet using the or operator send the parent ID too. This is effectively the same as only specifying the parent ID in the query.

I've fixed this in the attached patch. I'm not 100% sure about the approach, but from the testing I've done it's functionally correct. In our site, we have a heirarchical region/country facet, and with this patch applied we can select multiple countries without getting the results from entire regions like we did previously.

surfgatinho’s picture

@rupertj

Many thanks for this - it seems to work exactly as described.

Apologies for taking so long to test this and get back to you.

Chris

cpliakas’s picture

Status: Needs review » Postponed (maintainer needs more info)
Issue tags: -hierarchy

Thanks for highlighting the use case.

I would actually make the argument that the OR operator shouldn't be used to achieve the result you are looking for. How the Apache Solr Search module handles this use case is that it indexes the parent term along with the child so that hierarchy drill-downs work as expected.

For example, in your use case I am assuming that there is a City node that is only tagged with "City2". When Apache Solr Search indexes the node, it actually will actually associate both the "West of country" and "City2" terms with the node so that it can traverse the hierarchy as expected using the AND operator.

I believe the Search API module has a configuration option to use the same behavior. Marking as "maintainer needs more info" because that is the route I would take.

Thanks for posting,
Chris

cpliakas’s picture

StatusFileSize
new332.71 KB

Screenshot below showing setting in Search API:

tatyana’s picture

Worked for us too, thanks a lot!

jibize’s picture

StatusFileSize
new258.86 KB
new256.91 KB
new173.56 KB

The patch from rupertj (almost) worked for me as well, the problem is when using the current search block the parent term is missing which is expected because it has been removed from the query however this is not the desire behaviour, I expect it will cause more problems with other modules relying on the query.

Bellow some screenshots to illustrate the problem (and give more info to cpliakas).

Additional information:

I have a vocabulary called location set as follow:
BELGIUM
- Charleroi
- Liège
UK
- London
- Leeds
- ...
FRANCE
- Paris
- Lyon
- ...

I use Search API and Facet API to filter venues using the location vocabulary, the venues are saved with both the country and the city (full hierarchy).

jibize’s picture

Status: Postponed (maintainer needs more info) » Needs work
strykaizer’s picture

I tried the patch in #1. It was partly working, some issues I experienced with #1 are
- when unselecting a child term, the parent term is also unselected.
- facet api pretty paths are broken

I altered the patch so it would also work without those 2 issues. To use my patch, you should NOT patch facetapi, but patch the facetapi implementation in search api

You can find the new patch for search_api here:
https://www.drupal.org/node/2450227#comment-9708391

I have no experience with the apachesolr module, so I hope somebody else can write a solution for that implementation.

aron novak’s picture

I re-rolled the patch, now it can be applied for the latest dev.
It would be great to solve it in FacetAPI, as for instance you implement a custom hierarchical facet, the taxonomy term-only solution does not help.
Indeed the parents are de-selected in this case, I will work further on the patch to avoid that.

aron novak’s picture

Status: Needs work » Needs review
StatusFileSize
new5.31 KB

I updated the code, introduced a 3rd state for the filtering components (disabled, in addition to active and inactive). I tested with a custom 2-level hierarchy and it worked well. Code reviews, suggestions are highly appreciated, especially on reducing the amount of code that's needed to achieve this goal.

cutmedia’s picture

The last patch works but floods the site with warnings

Notice: Undefined variable: disabled_original in FacetapiUrlProcessorStandard->getQueryString() (line 51 of /home/test/public_html/sites/all/modules/facetapi/plugins/facetapi/url_processor_standard.inc).
Warning: array_search() expects parameter 2 to be array, null given in FacetapiUrlProcessorStandard->getQueryString() (line 51 of /home/test/public_html/sites/all/modules/facetapi/plugins/facetapi/url_processor_standard.inc).