I've been trying to tag a filter and then exclude it from the facet using the approach outlined here: http://shalinsays.blogspot.com/2009/04/tagging-and-excluding-filters.html

This functionality doesn't appear to work correctly in the module. Debugging through the code I can see the query being generated for Solr looks similar to this:

facet.field={!ex=field_star_rating}is_cck_field_star_rating&fq={!tag=is_cck_field_star_rating}is_cck_field_star_rating:5&

Note that the tag is "field_star_rating" but the exclusion is "is_cck_field_star_rating" so in this instance the facet is filtered to the result set and not the super set. The offending line of code seems to be line 475 in apachesolr_search.module where the exclusion is set to the delta and not the facet name.

Hope this helps.

Comments

idontknowtheanswer’s picture

Category: task » bug
idontknowtheanswer’s picture

Just to expand on this the behaviour only manifests itself when the facet block is set to "or". I think I've worked round the issue using the following code (note this is just a cut down example, additional sanity checks have been removed):

function mymodule_apachesolr_prepare_query(&$query, &$params, $caller) {
  
  foreach ($params['facet.field'] as $index => $facet) {
    
    // check if the facet has been setup to exclude a tag    
    if (strpos($facet, "!ex=")) {
      
      // get the solr cck field name
      $cck_field = substr($facet, strpos($facet, '}')+1);
      
      // rebuild the exclusion statement using the correct name
      $corrected_facet = '{!ex='. $cck_field .'}'. $cck_field;
      
      $params['facet.field'][$index] = $corrected_facet;
    }
  }
}

Would be interested to hear if this is an issue or whether I've misunderstood something.

Thanks,

jpmckinney’s picture

Assigned: Unassigned » jpmckinney
jpmckinney’s picture

Assigned: jpmckinney » Unassigned
Status: Active » Fixed

Fixed as part of #552152-12: OR facet counts are confusing. Only relevant to 6.x-2.x.

Status: Fixed » Closed (fixed)

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