Let's work a bit with grouping, just to jump start your own experimentation. First of all, we will search for the documents that simply contain the word painting,
and group the results by city, then obtain the first result and finally move to the next.
>> curl -X GET 'http://localhost:8983/solr/paintings/select?q=abstract:painting&start=2&rows=1&fl=artist_entity,title&group=on&group.facet=false&group.field=city_entity&group.limit=1&group.offset=0&group.ngroups=false&wt=json&indent=true'
The output of this query is as shown in the following screenshot:
The result will contain a section, as shown in the following screenshot:
On executing the query again, asking for the second group this time (remember that the second group will have group.offset=1
), we will get the following result:
It's clear that this is not the best visualization for our data, but I feel we have to play again with these kind of JSON raw results before putting them into appropriate HTML in order to have a good understanding of what's happening. The next step for sorting the group results would probably be to use these results from a carousel HTML widget or similar UX patterns.
We started with the first query, where we activated the grouping capability (group=on
) and projected only three fields in the results (fl=artist_entity,title
). At this point, we need to choose a field whose values will be used to group the results (group.field=city_entity
).
The first part is needed for the process to start working, then we need to think about results in a similar way to what we usually do when paginating. We are only selecting a certain amount of results (start=2
, rows=1
) but not dividing the groups in pages. The group pagination is then required with separate parameters; for example, the parameters group.offset=1
and group.limit=1
will start from the second result (we always start from 0!) and offer only one result at a time. You may think about group.offset
and group.limit
as a sort of the start
and rows
parameters to be used internally in the groups.
For example, we moved to the next result for the same group by simply incrementing the group.offset
value (imagine accomplishing this by clicking on an HTML widget):
>> curl -X GET 'http://localhost:8983/solr/paintings/select?q=abstract:painting&start=2&rows=1&fl=artist_entity,title&group=on&group.facet=false&group.field=city_entity&group.limit=1&group.offset=1&group.ngroups=false&wt=json&indent=true'
Finally, I have added two parameters that we have not used earlier: group.facet
to create faceting over groups and group.ngroups
to manage nested groups.
18.117.230.81