Search code examples
searchsolrindexinglucenefaceted-search

Selectively setting the number of returned SOLR rows per field based on field name


I have a field in my SOLR index, let's call it book_title.

A query returns 15 rows with book_title:"The Kite Runner", 13 rows with book_title:"The Stranger", and 8 rows with book_title:"The Ruby Way".

Is there a way to return only the first row of "The Kite Runner" and "The Stranger", but all of the "The Ruby Way" rows from the previous query result? This would result in 10 rows altogether. Is this possible at all, using a single query?


Solution

  • No, the variable amount of documents are, as far as I know, not possible. But you can use FieldCollapsing / Grouping to get an overview with 8 documents for each, if that's what you want - and then ignore the seven other for "The Kite Runner" and "The Stranger". Another option is to first retrieve the collapsed / grouped set of documents, then issue a second query to get the complete result set for one of the selected groups.