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 <m...@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 <varun.vgu...@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 >> > >