The Facet API dependency system doesn't work with Search API Solr search. The reason is that Facet API expects the facet parameters to be added in the query type plugin, however the facet parameters are added in the SearchApiSolrService::getFacetParams() method. Therefore the facet data for all enabled facet fields is always retrieved from the server instead of only the fields whose dependencies were met.

If the parameters are able to be added in the query type plugin, then Facet API can control which ones are displayed or not. This might be tough since the query type plugins have to be backend agnostic in Search API. An example of this system in use is the Apache Solr Search Integration module's implementation of a query type plugin.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cpliakas’s picture

Issue tags: +Facet API integration

Adding Facet API integration tag.

drunken monkey’s picture

Project: Search API Solr » Search API
Component: Code » Facets

I don't really understand.

First off, this isn't Solr-specific, but is the same for the DB search.

Secondly, why shouldn't we be able to easily deactivate certain facets in the adapter (or in the type plugins)? I just don't have any idea how to do it, what must be done. I guess we have to filter the retrieved facets in SearchApiFacetapiAdapter::initActiveFilters()? How do we do that? Or does this come in at a different point?
Your (second) link didn't really help, I don't see anything related to dependencies there.

While this doesn't work, should we maybe clear the supported dependency plugins so users won't be confused by options that do nothing? (The better option would of course be if we could fix this in the next week/until 1.0.)

cpliakas’s picture

Thanks for posting. Didn't have time to look into the database stuff, so I am glad you picked that up.

In terms of how Facet API works, the facet data passed to the server (in Solr's instance this is the "params") are added in the execute() method of the query type plugin instance associated with the facet. If a facet's dependency isn't met, then Facet API doesn't execute the query type plugin for that facet and therefore no params are passed to the server. In Search API's instance the params are sent to the server for all facets, so facet data is calculated and returned by the server whether the dependency is met or not.

Just to illustrate this further, the reason why I passed the link to Apache Solr's query type plugin is just to highlight that that is where the params are set. In the Faceted Navigation for Search module, the execute() method of the query type plugins is where the SQL joins and conditions are added to the search query to "facet" the data.

If the execute() method isn't called, then that facet info is never even sent to the server. Therefore facet's that don't meet their dependencies are not displayed since there no data returned by the server to display. This is good from a performance standpoint as well because the dependencies end up acting on a server level as opposed to just not rendering them a display level.

Let me know if that makes sense.
~Chris

drunken monkey’s picture

Status: Active » Needs review
FileSize
3.69 KB

Thanks for the explanation! Now I understand the system better and think I know where it went wrong for us: We already added all enabled facets to the query (though not their filters) in $adapter->initActiveFilters(). I now just saved it there for later and only added them from the type plugins – and now dependencies seem to work perfectly! :D

Patch attached, please test (and, if possible, review – can we safely assume that we know the adapter or should I check if $this->adapter->addFacet() really exists?) – would be really great to have this for 1.0.

cpliakas’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the patch. Tested it out and it works as advertised. This is a MUCH more elegant and simple approach than I would have taken :-). Marking as RTBC, pretty psyched that the dependencies are working.

Regarding the $this->adapter->addFacet() method, I don't think we have to add a test since the code that calls it will only be called in the context of Search API.

Thanks for your attention to this,
Chris

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for making me aware, and testing!
Committed it.
I'm also very glad this is now working. :D

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

danielnolde’s picture

patch works like a charme - Thanks, Thomas!

danielnolde’s picture

Issue summary: View changes

Updated issue summary.