I have a large index of files. One of the fields I have is "content_type". This field stores the basic type for a file (i.e. pdf, image, video, document, spreadsheet, etc).
I'm running a search on files names (my "title" field). How can I structure the query so that it returns only a certain amoun开发者_如何转开发t of each type?
For example, say I have 1000 files with the word "work" in the title. I want to search for "work" in the title, but I want 5 results from each "content_type" returned first. (assuming that each specific content_type has 5 or more items). So on my search results page I can say:
1,000 items were found for "work"
Then I start listing listing the items, 5 for each type.
Can anyone help me build a query that will do this? I'm pretty new to Solr, but I'm hoping this can be done.
Seems basically you want to limit and group the results per content type.
Check out the Solr field Collapsing and grouping feature
This will help you to group the results per content type using group.field=content_type
The number of results in a group can be limited by group.limit=5
For the complete list of options refer to the link above.
And you can use the normal query parameters to search the results i.e. q=work
This feature is only available from the Solr 3.3 build.
精彩评论