Search code examples
solrsolrnetsolrjfieldcollapsing

Solr: one of each in all categories


I have product index at solr, product has category field and I need to select one product (better would be random) from each category, how query would look like?


Solution

  • if you are looking for sql group by feature,
    with solr 3.3 on-wards, it has the similar feature called FieldCollapsing

    Field Collapsing collapses a group of results with the same field value down to a single (or fixed number) of entries. For example, most search engines such as Google collapse on site so only one or two entries are shown, along with a link to click to see more results from that site. Field collapsing can also be used to suppress duplicate documents.