Based on the discussion at #1446824: Support the multi-select facet feature of Solr where the associated counts are maintained as if no contraints have been applied, it would be great if Apache Solr Search Integration could support the multi-select facet feature so that facet counts are displayed as if no constraints have been applied. More details can be found in the "Tagging and excluding Filters" section of the Solr wiki.

The short version of this feature request is that it would allow for Solr to provide the "summary output" functionality of Views contextual filters. Since Solr is specifically designed to calculating aggregate results like this, it would be a more efficient option. It would also allow for Solr to used for more navigational purposes.

Comments

cpliakas’s picture

Pulling directly from the Solr documentation for reference...

Tagging and excluding Filters

One can tag specific filters and exclude those filters when faceting. This is generally needed when doing multi-select faceting.

Consider the following example query with faceting:

q=mainquery&fq=status:public&fq=doctype:pdf&facet=on&facet.field=doctype

Because everything is already constrained by the filter doctype:pdf, the facet.field=doctype facet command is currently redundant and will return 0 counts for everything except doctype:pdf.

To implement a multi-select facet for doctype, a GUI may want to still display the other doctype values and their associated counts, as if the doctype:pdf constraint had not yet been applied. Example:

=== Document Type ===
  [ ] Word (42)
  [x] PDF  (96)
  [ ] Excel(11)
  [ ] HTML (63)

To return counts for doctype values that are currently not selected, tag filters that directly constrain doctype, and exclude those filters when faceting on doctype.

q=mainquery&fq=status:public&fq={!tag=dt}doctype:pdf&facet=on&facet.field={!ex=dt}doctype

cpliakas’s picture

To cross post, danielnolde successfully prototyped this functionality for Search API. Details are at http://drupal.org/node/1446824#comment-5634040, I am sure some of the logic would be relevant to Apache Solr Search Integration's implementation.

nick_vh’s picture

Tagged filters are already available in apachesolr?

see solr_base_query.test for examples :

$fq = array(
      '#local' => 'tag=impala',
      '#exclude' => FALSE,
      '#name' => 'model',
      '#value' => 'Impala',
);
$query = $this->_apachesolr_drupal_query("apachesolr_tests");
$query->addParam('fq', $fq);

works perfectly fine, it justs needs to be implemented. What is required from the apachesolr part to make this work with facetapi?

cpliakas’s picture

Well, there has to be a setting that allows a facet to used a tagged query. This would be a global Facet API setting. Then the Apache Solr Search Integration query type plugins would have to read this setting and set the parameter accordingly. This could be implemented completely in Apache Solr, however I want to make sure this isn't something that should be abstracted by Facet API like the "empty facet" configuration.

nick_vh’s picture

I'm fully open for any modifications we have to make to the facet api implementation so I propose that we delay this conversation until facetapi comes up with a general solution that apachesolr can implement afterwards. I'll keep track of the similar issue in facetapi issue queue to make sure I don't miss relevant information.

Pay attention because this kind of behavior is very hard to achieve in a non-solr environment and since facetapi works in any environment this might be tricky to generalize?

cpliakas’s picture

Pay attention because this kind of behavior is very hard to achieve in a non-solr environment and since facetapi works in any environment this might be tricky to generalize?

Agreed. This is why I am also open to the backends like Apache Solr providing this option via the adapter's settingsForm() method and handling it completely by itself without any modifications to Facet API. I do see Faceted Navigation for Search supporting this, however I haven't vetted that out completely. Regardless, I really don't think this is a major change. Just a setting provided by the adapter and a few lines of logic in the query type plugin to make the change. I don;t see myself working on this, but I might take a crack at it if a few weeks go by with no progress.

Thanks for your insight,
Chris

pwolanin’s picture

Status: Active » Fixed

We already do this for OR facets. What am I missing?

see in apachesolr, query_type.term.inc:

line 33:


   $ex = (FACETAPI_OPERATOR_OR != $operator) ? '' : "{!ex={$this->facet['field']}}";
   $query->addParam('facet.field', $ex . $this->facet['field']);

line 63:

    else {
      // OR facet.
      $local = "tag={$this->facet['field']}";
      $values = array_keys($active);
      if ($values) {
        $query->addFilter($this->facet['field'], '(' . implode(' OR ', $values) . ')', FALSE, $local);
      }
    }
nick_vh’s picture

Status: Fixed » Closed (fixed)
cpliakas’s picture

I feel foolish :-) Thanks for your attention to this.