Skip to content

Group Collapse Component

rmerizalde edited this page Apr 19, 2013 · 1 revision

The group collapse component allows doing group queries with group.limit > 1 but return only on document per group. In addition, it may return a field summary for multiple numeric fields. The summary includes min & max values.

For example, OpenCommerceSearch supports indexing all skus for a product and it will group all skus into a single document during query time. Most of the data is the same between skus (e.g. URL, title, brand, etc.). For other fields, we just want the value of the most relevant sku (e.g. image). However, there's some sku data that would be useful for the customer. On example is price and discount. The front-end may render the maximum discount or the price range for the skus that matched the query. This component is useful for such use case and prevents bloating the response with all the skus for each product.

This following excerpt shows how to add the component to solrconfig.xml

  <searchComponent name="groupCollapse" class="solr.GroupCollapseComponent" />

  <requestHandler name="/select" class="solr.SearchHandler">
    <lst name="defaults">
      <str name="echoParams">none</str>
      <int name="rows">20</int>
      <str name="defType">synonym_edismax</str>
      <str name="synonyms">true</str>
      <str name="synonyms.originalBoost">1.0</str>
      <str name="synonyms.synonymBoost">1.2</str>
      <str name="synonyms.disablePhraseQueries">true</str>
      <str name="synonyms.constructPhrases">false</str>
      <str name="qf">text^3 brandText^2 highest^3.5 high^2.5 medium^1.6 low^1.3 lowest^0.5</str>
      
      <str name="df">text</str>
      <str name="spellcheck">true</str>
      <str name="spellcheck.count">10</str>
      <str name="spellcheck.dictionary">textSpellCheck</str>
      <str name="spellcheck.collate">true</str>
      <str name="fl">productId,title,brand,isToos,salePriceUS,listPriceUS,discountPercentUS,urlUS,bayesianReviewAverage,reviews,isPastSeason,freeGiftbcs,image</str>
      <str name="groupcollapse">true</str>
      <str name="groupcollapse.fl">salePriceUS,listPriceUS,discountPercentUS</str>
    </lst>
    <arr name="last-components">
      <str>spellcheck</str>
      <str>groupCollapse</str>
    </arr>
  </requesthandler>

Here is an excerpt from response example that used use the field productId to group documents:

<lst name="groups_summary">
  <lst name="productId">
    <lst name="ABS0003">
      <lst name="listPriceUS">
        <float name="min">1301.95</float>
        <float name="max">1301.95</float>
      </lst>
      <lst name="discountPercentUS">
        <float name="min">15.0</float>
        <float name="max">15.0</float>
      </lst>
      <lst name="salePriceUS">
        <float name="min">1106.66</float>
        <float name="max">1106.66</float>
      </lst>
    </lst>
    <lst name="ABT0205">
      <lst name="listPriceUS">
        <float name="min">19.95</float>
        <float name="max">19.95</float>
      </lst>
      <lst name="discountPercentUS">
        <float name="min">65.0</float>
        <float name="max">65.0</float>
      </lst>
      <lst name="salePriceUS">
        <float name="min">6.98</float>
        <float name="max">6.98</float>
      </lst>
    </lst>
    <lst name="ABT0224">
      <lst name="listPriceUS">
        <float name="min">114.95</float>
        <float name="max">114.95</float>
      </lst>
      <lst name="discountPercentUS">
        <float name="min">55.0</float>
        <float name="max">55.0</float>
      </lst>
      <lst name="salePriceUS">
        <float name="min">51.73</float>
        <float name="max">51.73</float>
      </lst>
    </lst>
    <lst name="ABT0194">
      <lst name="listPriceUS">
        <float name="min">99.95</float>
        <float name="max">99.95</float>
      </lst>
      <lst name="discountPercentUS">
        <float name="min">65.0</float>
        <float name="max">65.0</float>
      </lst>
      <lst name="salePriceUS">
        <float name="min">34.98</float>
        <float name="max">34.98</float>
      </lst>
    </lst>
    <lst name="ABT0223">
      <lst name="listPriceUS">
        <float name="min">179.95</float>
        <float name="max">179.95</float>
      </lst>
      <lst name="discountPercentUS">
        <float name="min">40.0</float>
        <float name="max">40.0</float>
      </lst>
      <lst name="salePriceUS">
        <float name="min">107.97</float>
        <float name="max">107.97</float>
      </lst>
    </lst>
    <lst name="ABS0005">
      <lst name="listPriceUS">
        <float name="min">179.95</float>
        <float name="max">179.95</float>
      </lst>
      <lst name="discountPercentUS">
        <float name="min">25.0</float>
        <float name="max">25.0</float>
      </lst>
      <lst name="salePriceUS">
        <float name="min">134.96</float>
        <float name="max">134.96</float>
      </lst>
    </lst>
Clone this wiki locally