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 Sreekant Sreedharan <sr...@alamy.com> on 2015/09/15 14:00:21 UTC

Generating a document by group count and displaying the result

I have a requirement to group documents by count based on a particular field: 

So for example if you have the following three documents: 
   <doc>
          <id>1</id>
          <category>food</category>
          <body>car</body>
   </doc>
   <doc>
          <id>2</id>
          <category>travel</category>
          <body>car</body>
   </doc>
   <doc>
          <id>3</id>
          <category>food</category>
          <body>car</body>
   </doc>

A search with the query string 'car' based on a grouping based on the
'category' field should return something like:

   <doc>
          <id>1</id>
          <category>food</category>
          <body>car</body>
          <category_count>2</category_count>
   </doc>
   <doc>
          <id>2</id>
          <category>travel</category>
          <body>car</body>
          <category_count>1</category_count>
   </doc>
   <doc>
          <id>3</id>
          <category>food</category>
          <body>car</body>
          <category_count>2</category_count>
   </doc>

Is this possible?

Regards,
Sreekant



--
View this message in context: http://lucene.472066.n3.nabble.com/Generating-a-document-by-group-count-and-displaying-the-result-tp4229183.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Generating a document by group count and displaying the result

Posted by Sreekant Sreedharan <sr...@alamy.com>.
The solution we came up with is to do a faceted search and use a stylesheet
to 'flatten' the result.



--
View this message in context: http://lucene.472066.n3.nabble.com/Generating-a-document-by-group-count-and-displaying-the-result-tp4229183p4229712.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Generating a document by group count and displaying the result

Posted by Ronald Xiao <xi...@gmail.com>.
Solr Grouping is unlike to generate the response like that directly.
Solr group response result is grouped by field, while you want FLAT format
result.
Flattern result self should be easy task, but may cause another problem,
how to control Navigation/Pagination behavior?  that depends on your
application requirement.

Best,
Ronald

On Wed, Sep 16, 2015 at 11:39 AM, Erick Erickson <er...@gmail.com>
wrote:

> Have you looked at the group by options? See:
> https://cwiki.apache.org/confluence/display/solr/Result+Grouping
>
> Best,
> Erick
>
> On Tue, Sep 15, 2015 at 5:00 AM, Sreekant Sreedharan
> <sr...@alamy.com> wrote:
> > I have a requirement to group documents by count based on a particular
> field:
> >
> > So for example if you have the following three documents:
> >    <doc>
> >           <id>1</id>
> >           <category>food</category>
> >           <body>car</body>
> >    </doc>
> >    <doc>
> >           <id>2</id>
> >           <category>travel</category>
> >           <body>car</body>
> >    </doc>
> >    <doc>
> >           <id>3</id>
> >           <category>food</category>
> >           <body>car</body>
> >    </doc>
> >
> > A search with the query string 'car' based on a grouping based on the
> > 'category' field should return something like:
> >
> >    <doc>
> >           <id>1</id>
> >           <category>food</category>
> >           <body>car</body>
> >           <category_count>2</category_count>
> >    </doc>
> >    <doc>
> >           <id>2</id>
> >           <category>travel</category>
> >           <body>car</body>
> >           <category_count>1</category_count>
> >    </doc>
> >    <doc>
> >           <id>3</id>
> >           <category>food</category>
> >           <body>car</body>
> >           <category_count>2</category_count>
> >    </doc>
> >
> > Is this possible?
> >
> > Regards,
> > Sreekant
> >
> >
> >
> > --
> > View this message in context:
> http://lucene.472066.n3.nabble.com/Generating-a-document-by-group-count-and-displaying-the-result-tp4229183.html
> > Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: Generating a document by group count and displaying the result

Posted by Erick Erickson <er...@gmail.com>.
Have you looked at the group by options? See:
https://cwiki.apache.org/confluence/display/solr/Result+Grouping

Best,
Erick

On Tue, Sep 15, 2015 at 5:00 AM, Sreekant Sreedharan
<sr...@alamy.com> wrote:
> I have a requirement to group documents by count based on a particular field:
>
> So for example if you have the following three documents:
>    <doc>
>           <id>1</id>
>           <category>food</category>
>           <body>car</body>
>    </doc>
>    <doc>
>           <id>2</id>
>           <category>travel</category>
>           <body>car</body>
>    </doc>
>    <doc>
>           <id>3</id>
>           <category>food</category>
>           <body>car</body>
>    </doc>
>
> A search with the query string 'car' based on a grouping based on the
> 'category' field should return something like:
>
>    <doc>
>           <id>1</id>
>           <category>food</category>
>           <body>car</body>
>           <category_count>2</category_count>
>    </doc>
>    <doc>
>           <id>2</id>
>           <category>travel</category>
>           <body>car</body>
>           <category_count>1</category_count>
>    </doc>
>    <doc>
>           <id>3</id>
>           <category>food</category>
>           <body>car</body>
>           <category_count>2</category_count>
>    </doc>
>
> Is this possible?
>
> Regards,
> Sreekant
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Generating-a-document-by-group-count-and-displaying-the-result-tp4229183.html
> Sent from the Solr - User mailing list archive at Nabble.com.