"Updating" facets after search results have been modified in a hook?

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

I am using the hook_apachesolr_process_results to modify the result set returned by Solr search. However, the enabled filters/facets do not reflect the modifications to the result set. How can I ensure that the facets reflect the changes to the results?

Thanks!

Comments

You're talking about Facet

milesw's picture

You're talking about Facet API facets? I would guess Facet API is pulling the results from the static cache. The static cache clones the full response object, so any changes you make in hook_apachesolr_process_results() won't be reflected in the facets. See apachesolr_static_response_cache().

Not sure what you're trying to accomplish, but you might be better off modifying the query before it goes to Solr. You can do most kinds of filtering using Solr params. If the data you need is not stored in Solr, consider adding it through something like hook_apachesolr_index_documents_alter().

milesw, Thanks for the

vivekisontrack's picture

milesw,

Thanks for the insight into apache_static_response_cache. I am looking into whether I can work with that to cache my altered response object.

Initially, I tried modifying the query before it went to Solr, but I wasn't quite able to get it to perform the filter I needed. I need the logical equivalent of the following:

([search terms] AND (content_type != XXX OR (content_type == XXX AND (author == logged_in_user OR particular_cck_field_checked_true))))

If you have any ideas on how to accomplish that... I'm all ears!

Thanks,
Vivek

Vivek, That query looks

milesw's picture

Vivek,

That query looks doable. And if your cck field is already indexed for facets, all those field should be in Solr already.

I imagine it would look something like: ?q="search terms" AND (-bundle:name OR (bundle:name AND (is_uid:7 OR cck_field:1)))

Testing directly on the Solr instance outside of Drupal would probably be easier. It might also be possible to accomplish this with the Solr client bundled with the Drupal module. The classes in Solr_Base_Query.php let you nest subqueries and choose the boolean operator used.

milesw, I will try to test

vivekisontrack's picture

milesw,

I will try to test that outside of Drupal and tweak it as necessary. Thanks for the heads up about Solr_base_query.php! That may turn out to be useful.

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