Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOLR - How to have facet counts restricted to rows returned in resultset

Tags:

search

solr

facet

/select/?q=*:*&rows=100&facet=on&facet.field=category

I have around 100 000 documents indexed. But I return only 100 documents using rows=100. The facet counts returned for category, however return the counts for all documents indexed.

Can we somehow restrict the facets to the result set returned? i.e 100 rows only?

like image 600
user489895 Avatar asked Oct 28 '10 11:10

user489895


2 Answers

I don't think it is possible in any direct manner, as was pointed out by Pascal.

I can see two ways to achieve this:

  1. Method I: do the counting yourself visiting the 100 results returned. This is very easy and fast if they are categorical fields, but harder if they are text fields that need to be tokenized, etc.

  2. Method II: do two passes:

    1. Do a normal query without facets (you only need to request doc ids at this point)
    2. Collect all the IDs of the documents returned
    3. Do a second query for all fields and facets, adding a filter to restrict result to those IDs collected in setp 2. Something like:
      select/?q=:&facet=on&facet.field=category&fq=id:(312 OR 28 OR 1231 ...)

The first is way more efficient and I would recommend for non-textual filds. The second is computationally expensive but has the advantage of working for all types od fields.

like image 150
Hugo Zaragoza Avatar answered Nov 19 '22 12:11

Hugo Zaragoza


Sorry, but i don't think it is possible. The facets are always based on all the documents matching the query.

like image 2
Pascal Dimassimo Avatar answered Nov 19 '22 12:11

Pascal Dimassimo