Skip to content

Instantly share code, notes, and snippets.

@zerolab
Last active December 14, 2015 09:29
Show Gist options
  • Save zerolab/5065610 to your computer and use it in GitHub Desktop.
Save zerolab/5065610 to your computer and use it in GitHub Desktop.
Drupal Apache Solr: prevent facet's filtering influence on facet item count
<?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