Last active
December 14, 2015 09:29
-
-
Save zerolab/5065610 to your computer and use it in GitHub Desktop.
Drupal Apache Solr: prevent facet's filtering influence on facet item count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add tags to fq and facet.field fields to exclude each facet's filtering | |
// from influencing its own facet item count | |
// @see http://drupal.org/node/1446824#comment-5634040 | |
$params = $query->getParams(); | |
$fq = $params['fq']; | |
if (!empty($fq)) { | |
$facet_field = $params['facet.field']; | |
foreach ($facet_field as $idx => $facet) { | |
$tag = "PREFIX_$facet"; | |
$facet_field[$idx] = "{!ex=$tag}". $facet; | |
foreach ($fq as &$option) { | |
$label_end_pos = strpos($option, ':'); | |
$label = substr($option, 0, $label_end_pos); | |
if ($label == $facet) { | |
$option = "{!tag=$tag}". $option; | |
} | |
} | |
} | |
$query->replaceParam('fq', $fq); | |
$query->replaceParam('facet.field', $facet_field); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment