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 Luis Carlos Guerrero Covo <lc...@gmail.com> on 2013/05/09 19:30:04 UTC

Grouping search results by field returning all search results for a given query

Hi,

I'm using solr to maintain an index of items that belong to different
companies. I want the search results to be returned in a way that is fair
to all companies, thus I wish to group the results such that each company
has 1 item in each group, and the groups of results should be returned
sorted by score.

example:
----------------------

20 companies

first 100 results

1-20 results - (company1 highest score item, company2 highest score item,
etc..)
20-40 results - (company1 second highest score item, company 2 second
highest score item, etc..)
...

 ----------------------

I'm trying to use the field collapsing feature but I have only been able to
create the first group of results by using
group.limit=1,group.field=companyid. If I raise the group.limit value, I
would be violating the 'fairness rule' because more than one result of a
company would be returned in the first group of results.

Can I achieve the desired search result using SOLR, or do I have to look at
other options?

thank you,

Luis Guerrero

Re: Grouping search results by field returning all search results for a given query

Posted by Jason Hellman <jh...@innoventsolutions.com>.
I would think pagination is resolved by obtaining the numFound value for your returned groups.  If you have numFound=6 then each page of 20 items (one item per company) would imply a total of 6 pages.

You'll have to arbitrate for the variance here…but it would seem to me you need as many "pages" as the highest value in the numFound field for all groups.  This shouldn't require requerying but will definitely require a little intelligence on the web app to handle the groups that are less than the largest size.

Hope that's useful!

On May 9, 2013, at 12:23 PM, Luis Carlos Guerrero Covo <lc...@gmail.com> wrote:

> Thank you for the prompt reply jason. The group.offset parameter is working
> for me, now I can iterate through all items for each company. The problem
> I'm having right now is pagination. Is there a way how this can be
> implemented out of the box with solr?
> 
> Before I was using the group.main=true for easy pagination of results, but
> it seems like I'll have to ditch that and use the standard grouping format
> returned by solr for the group.offset parameter to be useful. Since all
> groups don't have the same number of items, I'll have to carefully
> calculate the results that should be returned for each page of 20 items and
> probably make several solr calls per page rendered.
> 
> 
> On Thu, May 9, 2013 at 1:07 PM, Jason Hellman <
> jhellman@innoventsolutions.com> wrote:
> 
>> Luis,
>> 
>> I am presuming you do not have an overarching grouping value here…and
>> simply wish to show a standard search result that shows 1 item per company.
>> 
>> You should be able to accomplish your second page of desired items (the
>> second item from each of your 20 represented companies) by using the
>> group.offset parameter.  This will shift the position in the returned array
>> of documents to the value provided.
>> 
>> Thus:
>> 
>> group.limit=1&group.field=companyid&group.offset=1
>> 
>> …would return the second item in each companyid group matching your
>> current query.
>> 
>> Jason
>> 
>> On May 9, 2013, at 10:30 AM, Luis Carlos Guerrero Covo <
>> lcguerrerocovo@gmail.com> wrote:
>> 
>>> Hi,
>>> 
>>> I'm using solr to maintain an index of items that belong to different
>>> companies. I want the search results to be returned in a way that is fair
>>> to all companies, thus I wish to group the results such that each company
>>> has 1 item in each group, and the groups of results should be returned
>>> sorted by score.
>>> 
>>> example:
>>> ----------------------
>>> 
>>> 20 companies
>>> 
>>> first 100 results
>>> 
>>> 1-20 results - (company1 highest score item, company2 highest score item,
>>> etc..)
>>> 20-40 results - (company1 second highest score item, company 2 second
>>> highest score item, etc..)
>>> ...
>>> 
>>> ----------------------
>>> 
>>> I'm trying to use the field collapsing feature but I have only been able
>> to
>>> create the first group of results by using
>>> group.limit=1,group.field=companyid. If I raise the group.limit value, I
>>> would be violating the 'fairness rule' because more than one result of a
>>> company would be returned in the first group of results.
>>> 
>>> Can I achieve the desired search result using SOLR, or do I have to look
>> at
>>> other options?
>>> 
>>> thank you,
>>> 
>>> Luis Guerrero
>> 
>> 
> 
> 
> -- 
> Luis Carlos Guerrero Covo
> M.S. Computer Engineering
> (57) 3183542047


Re: Grouping search results by field returning all search results for a given query

Posted by Luis Carlos Guerrero Covo <lc...@gmail.com>.
Thank you for the prompt reply jason. The group.offset parameter is working
for me, now I can iterate through all items for each company. The problem
I'm having right now is pagination. Is there a way how this can be
implemented out of the box with solr?

Before I was using the group.main=true for easy pagination of results, but
it seems like I'll have to ditch that and use the standard grouping format
returned by solr for the group.offset parameter to be useful. Since all
groups don't have the same number of items, I'll have to carefully
calculate the results that should be returned for each page of 20 items and
probably make several solr calls per page rendered.


On Thu, May 9, 2013 at 1:07 PM, Jason Hellman <
jhellman@innoventsolutions.com> wrote:

> Luis,
>
> I am presuming you do not have an overarching grouping value here…and
> simply wish to show a standard search result that shows 1 item per company.
>
> You should be able to accomplish your second page of desired items (the
> second item from each of your 20 represented companies) by using the
> group.offset parameter.  This will shift the position in the returned array
> of documents to the value provided.
>
> Thus:
>
> group.limit=1&group.field=companyid&group.offset=1
>
> …would return the second item in each companyid group matching your
> current query.
>
> Jason
>
> On May 9, 2013, at 10:30 AM, Luis Carlos Guerrero Covo <
> lcguerrerocovo@gmail.com> wrote:
>
> > Hi,
> >
> > I'm using solr to maintain an index of items that belong to different
> > companies. I want the search results to be returned in a way that is fair
> > to all companies, thus I wish to group the results such that each company
> > has 1 item in each group, and the groups of results should be returned
> > sorted by score.
> >
> > example:
> > ----------------------
> >
> > 20 companies
> >
> > first 100 results
> >
> > 1-20 results - (company1 highest score item, company2 highest score item,
> > etc..)
> > 20-40 results - (company1 second highest score item, company 2 second
> > highest score item, etc..)
> > ...
> >
> > ----------------------
> >
> > I'm trying to use the field collapsing feature but I have only been able
> to
> > create the first group of results by using
> > group.limit=1,group.field=companyid. If I raise the group.limit value, I
> > would be violating the 'fairness rule' because more than one result of a
> > company would be returned in the first group of results.
> >
> > Can I achieve the desired search result using SOLR, or do I have to look
> at
> > other options?
> >
> > thank you,
> >
> > Luis Guerrero
>
>


-- 
Luis Carlos Guerrero Covo
M.S. Computer Engineering
(57) 3183542047

Re: Grouping search results by field returning all search results for a given query

Posted by Jason Hellman <jh...@innoventsolutions.com>.
Luis,

I am presuming you do not have an overarching grouping value here…and simply wish to show a standard search result that shows 1 item per company.

You should be able to accomplish your second page of desired items (the second item from each of your 20 represented companies) by using the group.offset parameter.  This will shift the position in the returned array of documents to the value provided.

Thus:

group.limit=1&group.field=companyid&group.offset=1

…would return the second item in each companyid group matching your current query.

Jason

On May 9, 2013, at 10:30 AM, Luis Carlos Guerrero Covo <lc...@gmail.com> wrote:

> Hi,
> 
> I'm using solr to maintain an index of items that belong to different
> companies. I want the search results to be returned in a way that is fair
> to all companies, thus I wish to group the results such that each company
> has 1 item in each group, and the groups of results should be returned
> sorted by score.
> 
> example:
> ----------------------
> 
> 20 companies
> 
> first 100 results
> 
> 1-20 results - (company1 highest score item, company2 highest score item,
> etc..)
> 20-40 results - (company1 second highest score item, company 2 second
> highest score item, etc..)
> ...
> 
> ----------------------
> 
> I'm trying to use the field collapsing feature but I have only been able to
> create the first group of results by using
> group.limit=1,group.field=companyid. If I raise the group.limit value, I
> would be violating the 'fairness rule' because more than one result of a
> company would be returned in the first group of results.
> 
> Can I achieve the desired search result using SOLR, or do I have to look at
> other options?
> 
> thank you,
> 
> Luis Guerrero