Keeping Facet Counts when filtering query

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
kmoll's picture

I am using Apachesolr module with Drupal 6. I have only one facet so far on my searching and that is the node type. I have a list of links that is supposed to filter the query. When I put in a search term, I get all the matching results and the list of links with the correct counts for each node type. However, when I click a node type it returns just the result for that node type, but now all the counts in my link list have turned to 0, except for that node type which shows the correct amount, I have it set a $_REQUEST['filter'] parameter. In my hook_solrsearch_apachesolr_prepare_query, I check for the existence and value of this filter. To filter the query I use $query->add_filter('type', 'node_type');. I have also tried setting the ['fq'] in that hook with $params['fq'][] = 'type:node_type', but that has no effect on the results.

I generate the list of links by setting $response = apachesolr_static_response_cache(); and using $response->response->numFound->facet_fields->type->node_type.

I know I am missing something here, but I can't figure out what. When the query runs with the filter for a certain node type, it is only logical that $response->response->numFound->facet_fields->type->node_type would return a count of 0 for all other node types.

How can I filter the results by the node type the way I would like to, but keep my counts for the Type facet correct for all other node types? Drupal.org does this really well. Anyone know how that can be accomplished.

Comments

I think you need to look at

janusman's picture

I think you need to look at doing an or facet; this means that you could select a single facet value but still get counts for the other facet values.

See http://wiki.apache.org/solr/SimpleFacetParameters#Tagging_and_excluding_...

revisited this

kmoll's picture

Hi janusman,

I was able to revisit this issue, and you link was incredibly helpful. I am able to get exactly what I need. But I have to do it a little different then I would have though. I read through many posts about this and it seems there was a big push to have this working correctly in apachesolr 6.x.2.x-dev, but I beleive that branch has been abandoned. What I needed to do was create some link, not neccessarilly the exact facets, but some were a combination of facets, so I created a url parameter and in the hook_prepare_query(&$query, &$params) and I change the $params[facet.field] to {!ex=tag} and I add in the $params[fq] = {!tag=tag}type:type1, and I get the counts I need and it still filters the results the way I need.

A problem I ran into, was that I could not add a filter with a tag using add_filter(); I had to just add it to the $params['fq'] array. But if I have apachesolr_nodeaccess enabled, its use of add_filter() seems to wipe out the parameter I add in in my module. I disabled it, because I actually don't restrict the access to view any nodes on my side, especially the ones being indexed in the search. Is there a better way to be able to add the tag using $query->add_filter(). Or does there need to be. I am digging pretty deep into the module and getting a better understanding of the way it all works, and would help out if this is a direction the module should go in, and if it isn't already done. I would like the ability to be able to turn that module back on and still have the search work the way I would like it too. Again, thanks for your help, sorry for the very long delay, I had moved onto another project for a while and am finally able to return to this one.

Thanks

Lucene, Nutch and Solr

Group organizers

Group categories

Projects

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week