I am using search_api with solr and have a category checkbox facet on a views-based search page. Category facet looks like this (simplified):

[x] Accounting (20)
[x] - Account Clerks (10)
[0] - Accounts Payable (10)
[x] Finance (20)
[0] Technology (20)

The facet operator is set to "OR", so if I wanted I could have Accounting and Finance checked, but not technology. That works just fine, but I'm having a problem when it comes to child terms. I want only Account Clerk, and not Accounts Payable, but I'm getting the entire Accounting results set since the parent is checked. So really it doesn't matter at all whether or not child terms are checked, they will always show if their parent is checked (and if you uncheck the parent, the children are automatically unchecked).

Is there something that I'm doing wrong with my setup, or is this expected behavior, or.. is this a bug?

Edit: In the node, the parent term is not selected (just the child)

Comments

cpliakas’s picture

Status: Active » Closed (won't fix)

Hi jarchowk.

Thanks for the post. Judging by what you are saying this isn't Facet API's responsibility and should probably be posted against the backend module you are using. Facet API is responsible for displaying the results, whereas the backend is responsible indexing the results, querying the results, and determining the facet counts which is where this issue is being introduced.

From a Solr standpoint, the module work by indexing all terms associated with the hierarchy. So for example, take the following hierarchy:

Fruit: 1
  - Apple: 2
  - Orange: 3
Veggies: 4
  - ...

If you had a document tagged with "Apple", that document would index values 1 and 2. If you had a document tagged with "Orange", it would index values 1 and 3. Therefore by what you are trying to do, the application is working exactly as designed. You are effectively adding an "OR Fruit" clause when the parent is selected, so it will match all documents with a tid of "1". I am not sure what the right approach is to solving this issue, as the way the module indexes content would probably have to change. I am wondering whether the techniques at http://wiki.apache.org/solr/HierarchicalFaceting would help. Either way, that change has to happen outside of Facet API.

Thanks,
Chris

jarchowk’s picture

Ok I think I understand the issue a little more. Reading the link you provided, if I understand correctly, could providing a prefix argument fix this problem? Using your fruit/veg example, use "facet.prefix = 2/Fruit/Apple" to limit the facets to the child.

jarchowk’s picture

Status: Closed (won't fix) » Active

I found something interesting that makes me think that this is not a limitation of solr setup itself. I'm building links to some of the child-level category result pages, and I was surprised to see that it works as expected.

So linking directly to (using your example) search?f[0]=category:apple only displays the Apple results, not the Orange results. (Btw, the main "Fruit" facet is checked, but it is not listed in the f querystring param.)

So I'm going to push back here and say that this could be an issue with facetapi. If a child level facet is selected, then should the parent filter term be remove from the filter params?

cpliakas’s picture

Status: Active » Closed (won't fix)

Sorry for closing this again, but I would really start with the backend since Facet API does not handle the indexing, count calculation, or filtering of the results. If you can point to a specific line of code in Facet API that is causing this bug then I will be happy to work with you, otherwise all of the symptoms outlined above are outside of Facet API's responsibility and handled by the individual backends implementing the API.

cpliakas’s picture

Status: Closed (won't fix) » Postponed (maintainer needs more info)

Let me un-close this. I think that a "needs more info" is probably a friendlier and more applicable status.

jarchowk’s picture

Hm. I'm out of office here so I can't check code, but I cant see how this is an indexing problem since I can get the correct facet results by intentionally leaving out the parent term. If drill down into the facets, selecting Fruits, then Apples, it should not be "Fruits OR Apples", it should now be just "Apples". First maybe I should understand if you agree with that logic?

If you do agree, then why is it not a bug that facet API logically interprets a child selection as being "everything marked fruits OR everything marked apples".

I'm new to facet API so please let me know if I'm off here.

cpliakas’s picture

Status: Postponed (maintainer needs more info) » Active

OK, I think I see where you are going with this, and thanks for the clarification. Give me a little bit to think through the use cases and implications.

Thanks,
Chris

cpliakas’s picture

I think based on the comments in #6 this is valid, but I am not sure where the best place to add this is. Trying to code up a patch so we can start working on this with a base of functionality to start hacking from.

raphael apard’s picture

I'm working on a project and i've got the same issue.
Here a quick patch (1.x-dev / 1.0-rc4) to fix this (it's worked for me), but i'm pretty sure this is not the best way to fix this.
I did'nt find another place to fix this than in the contrib module "search_api_facetapi" of "search_api".

cpliakas’s picture

Project: Facet API » Search API
Version: 7.x-1.0-rc4 » 7.x-1.x-dev
Component: User interface » Facets
Category: bug » feature

Based on #9, I am thinking this is a feature request against Search API? If there is some way to make this agnostic to the backend I am willing to add it to Facet API, but seeing how the feature is added to Search API is makes more sense to punt it over to the Search API issue queue.

cpliakas’s picture

Issue summary: View changes

Node status

nick_vh’s picture

Title: Hierarchy "OR" operator issue » When clicking a hierarchy facet, I do want to include the parent AND the child even if the facet is configured as an OR
Version: 7.x-1.x-dev » 8.x-1.x-dev
Issue summary: View changes

I'd like to add some context here for this problem that got solved in Apache Solr & Facet API

https://drupal.org/project/apachesolr_exclude_parent_terms

Seeing that we're moving soon with D8 I'm bumping it up and it should certainly get a backport if that seems possible

drunken monkey’s picture

Makes sense. I'm open for D7 patches too, though, as long as we haven't started with facets in D8 anyways.

drunken monkey’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev
Category: Feature request » Bug report

I think this makes more sense in D7 right now. In D8, we should of course strive to get this right the first time.

Also, in my eyes, that's a bug, not a feature request. Having hierarchical OR facets work the way they do now isn't really useful to anyone, I'd say.

arnaldoaa’s picture

[sorry I logged with the wrong user account] original user: @sebas5384

sebas5384’s picture

The last patch worked as expected!!
Rerolled and added a condition to avoid the hierarchy overload when is a flatten widget.

[this message were to be with this user]

sebas5384’s picture

This patch seems unnecessary in the last version of search api.

sebas5384’s picture

drunken monkey’s picture

This patch seems unnecessary in the last version of search api.

So now it's already working correctly for you?
Then maybe it was fixed in Facet API, because I don't think I've changed anything in that area.

Also, if a patch is still needed, it should take into account hierarchies in general, not only taxonomy terms. And, more importantly, you should be aware that the term query type applies to all fields except dates by default, it doesn't have anything to do with taxonomy terms (and, thus, is not just for them).

drunken monkey’s picture

Status: Active » Postponed (maintainer needs more info)
twod’s picture

The issue I just added changed how this behaves (and a few commits after made additional tweaks). It seems to do the opposite of what was requested in that it's now impossible to show a taxonomy as a hierarchy, but have them treated as individual terms. (Parent terms are removed, so OR queries including both a child and its parent are now broken.)

twod’s picture

Status: Postponed (maintainer needs more info) » Active

Forgot to change the state...

Btw, the patches above also seem to do the opposite of what the OP requested. I also want to make OR queries including parent and child, as some nodes are tagged with the parent, some with the child, some with both.
This works if I flatten the hierarchy, but then there's no point in having the hierarchy as terms can't be displayed as having a relationship...

Thinking about it, this should have worked as desired before any of the mentioned patches were applied...

drunken monkey’s picture

Can you give a real-world use case/example for this behavior? You're correct in that I don't think we currently support it, or even thought about it, but I also can't really imagine where this might really be handy.

Anyone else who wants this behavior? Then I guess we could make it configurable.

brunodbo’s picture

I'm looking for the following behavior (I think this is the right issue for it, apologies if it isn't):

- I have a taxonomy based facet for a vocabulary called 'Sewing pattern types', that has a 1 level hierarchy:

- Clothes
-- Dress
-- Shirt
-- Pants
- Curtains
-- Long curtains
-- Short curtains
etc

- When I select one of the parent terms, I would like the search to return results tagged with the child terms as well as the parent term. This currently doesn't happen: only results tagged with the parent term are returned.
- When I drill down further in the hierarchy, I'd like the parent term facet to become inactive. This currently works for me in the current version (if I understand correctly, that was the focus of #2450227: Ignore parent terms in facets when operator is OR).

Using Apache Solr. My facet operator is set to OR; 'Treat parent items as individual facet items' is set to 'No' (nothing changes when I set it to 'Yes').

drunken monkey’s picture

I'm looking for the following behavior (I think this is the right issue for it, apologies if it isn't):

No, it isn't, and it seems like you just need to add the "Index hierarchy" processor to the index.

benstallings’s picture

Status: Active » Closed (outdated)

I think we can safely say this is outdated.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.