10
votes

/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?

4

4 Answers

6
votes

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.

2
votes

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

0
votes

Not a real answer but maybe better than nothing: the results grouping feature (check out from trunk!):

http://wiki.apache.org/solr/FieldCollapsing

where facet.field=category is then similar to group.field=category and you will get only as much groups ('facet hits') as you specified!

0
votes

If you always execute the same query (q=*:*), maybe you can use facet.limit, for example:

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

Tell us if the order that solr uses is the same in the facet as in the query :.