You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Daniel Löfquist <da...@it.cdon.com> on 2009/08/20 14:40:23 UTC

Group by field in Solr

Hello,

I'm trying to accomplish something akin to "GROUP BY" in SQL but in Solr.
I have an index full of songs (one song per document in Solr) by various artists and I
would like to construct a search that gives me all of the artists back, one row per
artist. The current search returns one row per artist and song.

So I get this right now if I search after "war" in the artist-field:

30 Years War - Ideal Means
30 Years War - Dirty Castle
30 Years War - Misinformed
All Out War - Soaked In Torment
All Out War - Claim Your Innocence
Audio War - Negativity
Audio War - One Drug
Audio War - Super Freak

But this is what I'd really like:

30 Years War - whatever song
All Out War - whatever song
Audio War - whatever song

I tried using facets but couldn't get it to work properly. Anybody have a clue how to do
something like this?

//Daniel

Re: Group by field in Solr

Posted by Martijn v Groningen <ma...@gmail.com>.
Hi Daniel,

I think you should take a look at
https://issues.apache.org/jira/browse/SOLR-236. The functionality you
are looking for is called field collapsing in Solr and does grouping
by field. Currently this is not supported out of the box in Solr. The
jira issue contains a patch you that you can apply on the Solr trunk.
Take a look at http://wiki.apache.org/solr/FieldCollapsing for more
information on FieldCollapsing.

Cheers,

Martijn

2009/8/20 Daniel Löfquist <da...@it.cdon.com>:
> Hello,
>
> I'm trying to accomplish something akin to "GROUP BY" in SQL but in Solr.
> I have an index full of songs (one song per document in Solr) by various artists and I
> would like to construct a search that gives me all of the artists back, one row per
> artist. The current search returns one row per artist and song.
>
> So I get this right now if I search after "war" in the artist-field:
>
> 30 Years War - Ideal Means
> 30 Years War - Dirty Castle
> 30 Years War - Misinformed
> All Out War - Soaked In Torment
> All Out War - Claim Your Innocence
> Audio War - Negativity
> Audio War - One Drug
> Audio War - Super Freak
>
> But this is what I'd really like:
>
> 30 Years War - whatever song
> All Out War - whatever song
> Audio War - whatever song
>
> I tried using facets but couldn't get it to work properly. Anybody have a clue how to do
> something like this?
>
> //Daniel

Re: Group by field in Solr

Posted by Constantijn Visinescu <ba...@gmail.com>.
You'll want to use faceting, try to use a query like this

http://localhost:8080/Solr/select/?q=artist%3Awar&version=2.2&start=0&rows=0&facet=true&facet.limit=-1&facet.field=artist

replace localhost:8080 with your own :)

On Thu, Aug 20, 2009 at 2:40 PM, Daniel Löfquist <
daniel.lofquist@it.cdon.com> wrote:

> Hello,
>
> I'm trying to accomplish something akin to "GROUP BY" in SQL but in Solr.
> I have an index full of songs (one song per document in Solr) by various
> artists and I
> would like to construct a search that gives me all of the artists back, one
> row per
> artist. The current search returns one row per artist and song.
>
> So I get this right now if I search after "war" in the artist-field:
>
> 30 Years War - Ideal Means
> 30 Years War - Dirty Castle
> 30 Years War - Misinformed
> All Out War - Soaked In Torment
> All Out War - Claim Your Innocence
> Audio War - Negativity
> Audio War - One Drug
> Audio War - Super Freak
>
> But this is what I'd really like:
>
> 30 Years War - whatever song
> All Out War - whatever song
> Audio War - whatever song
>
> I tried using facets but couldn't get it to work properly. Anybody have a
> clue how to do
> something like this?
>
> //Daniel
>