solr grouping based on all index values

2019-08-08 19:41发布

问题:

When I group or facet in solr based on a field, I only receive a count of documents that are in the search results. Is there a way to get a count of the documents that contain that value across the entire index? For example, with this data, I would like to search for "something" and get back only one item per unique gs field with a count of all the fields in the index. So id 2 would come up, as grouped by gs 50005, but the count would be 2 instead of 1.

<doc>
<field name="id">1</field>
<field name="gs">50005</field>
<field name="text">blah</field>
</doc>

<doc>
<field name="id">2</field>
<field name="gs">50005</field>
<field name="text">something else</field>
</doc>

<doc>
<field name="id">3</field>
<field name="gs">123</field>
<field name="text">another something value</field>
</doc>

<doc>
<field name="id">4</field>
<field name="gs">5423</field>
<field name="text">something entirely different</field>
</doc>

回答1:

To my knowledge no. Why don't you add them up based on the facet counts in your client code?



回答2:

I have a work around: {!join from=gs to=gs}gs:field(gs) text:something&group=true&group.field=gs

Essentially, the way this works is the query is expanded through a join to include all items that have that same gs and then it is grouped by gs. Through grouping I have a value in XML of how many items are in the group.

Not very elegant, but should do the trick.



标签: solr grouping