Reputation: 6849
I have a very large number of documents stored in a SOLR index. I would like to perform a query that returns the Facet counts for a specified field, and the first 100 documents for each Facet field returned.
For example. Let's assume I have a bunch of books stored in my SOLR index.
{ name: "Book 1", genre: "Mystery" },
{ name: "Book 2", genre: "Science Fiction" },
{ name: "Book 3", genre: "Romance" },
{ name: "Book 4", genre: "Mystery" }
Now, I want to specify a Faceted query on a field, in this example, the book's genre. facet=true&facet.field=genre
. This search result may look something like:
"facet_fields":{
"genre":[
"Mystery",503322,
"Science Fiction",40759,
"Romance",23987
]
}
This gives me the number of books matching each genre. If I were to add a rows
parameter to my query, this would simply return to me the first N number of books that match the query.
However, I want to go one step further. I want SOLR to return to me the first 100 books of each genre that match my query. This means that, since 3 facet fields were returned (Mystery, Science Fiction, and Romance), this search might return up to 300 documents.
If possible, I would like this all to be executed within a single query. Am I able to do so? Do I need to query SOLR multiple times in order to get what I am looking for? If so, what is the recommended approach to get what I am looking for?
I'm fairly new to SOLR and just trying to get a grasp on what SOLR is and isn't capable of.
Upvotes: 3
Views: 1283
Reputation: 472
Have a look at the group option in Solr. For instance to get the first 100 documents for each genre
you would use group=true&group.field=genre&group.limit=100
.
Upvotes: 4