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 Varun Gupta <va...@gmail.com> on 2009/09/29 11:36:27 UTC
Showing few results for each category (facet)
Hi,
I am looking for a way to do the following in solr:
When somebody does a search, I want to show results by category (facet) such
that I display 5 results from each category (along with showing the total
number of results in each category which I can always do using the facet
search). This is kind of an overview of all the search results and user can
click on the category to see all the results pertaining to that category
(normal facet search with filter).
One way that I can think of doing this is by making as many queries as there
are categories and show these results under each category. But this will be
very inefficient. Is there any way I can do this ?
Thanks & Regards,
Varun Gupta
Re: Showing few results for each category (facet)
Posted by Varun Gupta <va...@gmail.com>.
Thanks Matt!! I will take a look at the patch for field collapsing.
Thanks Marian for pointing that out. If the field collapse does not work
then I will have to rely on solr caching.
Thanks,
Varun Gupta
On Wed, Sep 30, 2009 at 1:44 AM, Matt Weber <ma...@mattweber.org> wrote:
> So, you want to display 5 results from each category and still know how
> many results are in each category. This is a perfect situation for the
> field collapsing patch:
>
> https://issues.apache.org/jira/browse/SOLR-236
> http://wiki.apache.org/solr/FieldCollapsing
>
> Here is how I would do it.
>
> Add a field to your schema called category or whatever. Then while
> indexing you populate that field with whatever category the document belongs
> in. While executing a search, collapse the results on that field with a max
> collapse of 5. This will give you at most 5 results per category. Now, at
> the same time enable faceting on that field and DO NOT use the collapsing
> parameter to recount the facet vales. This means that the facet counts will
> be reflect the non-collapsed results. This facet should only be used to get
> the count for each category, not displayed to the user. On your search
> results page that gets the collapsed results, you can put a link that says
> "Show all X results from this category" where X is the value you pull out of
> the facet. When a user clicks that link you basically do the same search
> with field collapsing disabled, and a filter query on the specific category
> they want to see, for example: &fq=category:people.
>
> Hope this helps.
>
> Thanks,
>
> Matt Weber
>
>
> On Sep 29, 2009, at 4:55 AM, Marian Steinbach wrote:
>
> On Tue, Sep 29, 2009 at 11:36 AM, Varun Gupta <va...@gmail.com>
>> wrote:
>>
>>> ...
>>>
>>> One way that I can think of doing this is by making as many queries as
>>> there
>>> are categories and show these results under each category. But this will
>>> be
>>> very inefficient. Is there any way I can do this ?
>>>
>>
>>
>> Hi Varun!
>>
>> I think that doing multiple queries doesn't have to be inefficient,
>> since Solr caches subsequent queries for the same term and facets.
>>
>> Imagine this as your first query:
>> - q: xyz
>> - facets: myfacet
>>
>> and this as a second query:
>> - q:xyz
>> - fq: myfacet=a
>>
>> Compared to the first query, the second query will be very fast, since
>> all the hard work ahs been done in query one and then cached.
>>
>> At least that's my understanding. Please correct me if I'm wrong.
>>
>> Marian
>>
>
>
Re: Showing few results for each category (facet)
Posted by Matt Weber <ma...@mattweber.org>.
So, you want to display 5 results from each category and still know
how many results are in each category. This is a perfect situation
for the field collapsing patch:
https://issues.apache.org/jira/browse/SOLR-236
http://wiki.apache.org/solr/FieldCollapsing
Here is how I would do it.
Add a field to your schema called category or whatever. Then while
indexing you populate that field with whatever category the document
belongs in. While executing a search, collapse the results on that
field with a max collapse of 5. This will give you at most 5 results
per category. Now, at the same time enable faceting on that field and
DO NOT use the collapsing parameter to recount the facet vales. This
means that the facet counts will be reflect the non-collapsed
results. This facet should only be used to get the count for each
category, not displayed to the user. On your search results page that
gets the collapsed results, you can put a link that says "Show all X
results from this category" where X is the value you pull out of the
facet. When a user clicks that link you basically do the same search
with field collapsing disabled, and a filter query on the specific
category they want to see, for example: &fq=category:people.
Hope this helps.
Thanks,
Matt Weber
On Sep 29, 2009, at 4:55 AM, Marian Steinbach wrote:
> On Tue, Sep 29, 2009 at 11:36 AM, Varun Gupta
> <va...@gmail.com> wrote:
>> ...
>>
>> One way that I can think of doing this is by making as many queries
>> as there
>> are categories and show these results under each category. But this
>> will be
>> very inefficient. Is there any way I can do this ?
>
>
> Hi Varun!
>
> I think that doing multiple queries doesn't have to be inefficient,
> since Solr caches subsequent queries for the same term and facets.
>
> Imagine this as your first query:
> - q: xyz
> - facets: myfacet
>
> and this as a second query:
> - q:xyz
> - fq: myfacet=a
>
> Compared to the first query, the second query will be very fast, since
> all the hard work ahs been done in query one and then cached.
>
> At least that's my understanding. Please correct me if I'm wrong.
>
> Marian
Re: Showing few results for each category (facet)
Posted by Marian Steinbach <ma...@sendung.de>.
On Tue, Sep 29, 2009 at 11:36 AM, Varun Gupta <va...@gmail.com> wrote:
> ...
>
> One way that I can think of doing this is by making as many queries as there
> are categories and show these results under each category. But this will be
> very inefficient. Is there any way I can do this ?
Hi Varun!
I think that doing multiple queries doesn't have to be inefficient,
since Solr caches subsequent queries for the same term and facets.
Imagine this as your first query:
- q: xyz
- facets: myfacet
and this as a second query:
- q:xyz
- fq: myfacet=a
Compared to the first query, the second query will be very fast, since
all the hard work ahs been done in query one and then cached.
At least that's my understanding. Please correct me if I'm wrong.
Marian