質問

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?

役に立ちましたか?

解決 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.

他のヒント

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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top