Question

I am building an application in ruby on rails which makes use of Solr 4. To support Solr 4 in my application I am using the rSolr gem. I am trying to parse a query and let the resulting documents be grouped on a number. The querying doesn't form a problem, but I can't seem to find the correct syntax to tell rSolr to parse the group part. Does anyone know what the correct syntax is?

Was it helpful?

Solution 2

After a little research I found the answer to my problem. I was using functionality, the find method to be specific, from the rsolr-ext gem which doesn't support grouping:

solr_connection.find(
{
  :q => "*:*", 
  :group => true,
  "group.field" => "group_id"
})   

This will raise an error in the rsolr-ext gem because it can't parse the "group.field" part of the hash. Without it, Solr doesn't know where to group on.

The answer was quite simple. Just use the select method from the rsolr gem:

solr_connection.select(
{
  :q => "*:*", 
  :group => true,
  "group.field" => "group_id"
})

This works perfectly.

OTHER TIPS

This is how grouping is done in Solr 4:

&group=true
&group.field=myField

If you want only the groups and no documents, add this:

&rows=0
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top