>>So my question basically is: which restrictions are applied to the docset
from which (field) facets are computed?

Facets are generated based upon values found within the documents matching
your "q=" parameter and also all of your "fq=" parameters. Basically, if
you do an intersection of the docsets from all "q=" and "fq=" parameters
then you end up with the docset the facet calculations are based upon.

When you say "if I add type=book, *no* documents match, but I get facet
counts: { chapter=4 }", I'm not exactly sure what you mean. If you are
adding "q=toto&type=book&facet=true&facet.field=type" then the problem is
that the "type=book" parameter doesn't do anything... it is not a valid
Solr parameter for filtering here. In this case, all 4 of your documents
matching the "q=toto" query are still being returned, which is why the
facet count for chapters is 4.

If instead you specify "q=toto&fq=type:book&facet=true&facet.field=type"
then this will filter down to ONLY the documents with a type of book. Since
it looks like in your data there are no documents which are both a type of
book and also match the "q=toto" query, you should get 0 documents and thus
the counts of all your facet values will be zero.

As you mentioned, it is possible to utilize tags and excludes to change the
behavior described above, but hopefully this answers your question about
the default behavior.

Thanks,

Trey Grainger
Co-author, Solr in Action
Director of Engineering, Search & Analytics @ CareerBuilder


On Sun, Apr 27, 2014 at 4:51 PM, Michael Sokolov <
msoko...@safaribooksonline.com> wrote:

> I'm trying to understand the facet counts I'm getting back from Solr when
> the main query includes a term that restricts on a field that is being
> faceted.  After reading the docs on the wiki (both wikis) I'm confused.
>
> In my little test dataset, if I facet on "type" and use q=*:*, I get facet
> counts for type: [ chapter=5, book=1 ]
>
> With q=toto, only four of the chapters match, so I get facet counts for
> type: { chapter=4 } .
>
> Now if I add type=book, *no* documents match, but I get facet counts: {
> chapter=4 }.
>
> It's as if the type term from the query is being ignored when the facets
> are computed.  This is actually what we want, in general, but the
> documentation doesn't reflect it and I'd like to understand better the
> mechanism so I can tell what I can rely on.
>
> I see that there is the possibility of tagging and excluding filters (fq)
> so they don't effect the facet counting, but there's no mention on the wiki
> of any sort of term exclusion from the main query.  I poked around in the
> source a bit, but wasn't able to find an answer quickly, so I thought I'd
> ask here.
>
> So my question basically is: which restrictions are applied to the docset
> from which (field) facets are computed?
>
> -Mike
>
>
>

Reply via email to