如何使Solr查询返回按字段分组的结果

时间:2013-07-11 08:41:02

标签: solr

我喜欢在查询时引导Solr搜索结果。例如,我有三个频道:productsfaqother_docs。所有Solr核心都填充相同的字段。我想加入的是让Solr小组为我提供结果“渠道”。

示例数据库(csv):

id,channel,name,desc
1,product,Some product,This is an very cool product!
2,product,Other product,This is an other product!
3,faq,How to stuff,This time: Simply do it!
4,other_docs,Legal notice,All your base are belong to us!

通缉查询结果(xml):

<?xml version="1.0" encoding="UTF-8"?>
<response>

<lst name="grouped">
  <lst name="channel">
    <int name="matches">3</int>
    <arr name="groups">
      <lst>
        <str name="groupValue">product</str>
        <result name="doclist" numFound="2" start="0">
          <doc>
            <str name="name">Some product</str>
            <str name="desc">This is an very cool product!</str></doc>
          <doc>
            <str name="name">Other product</str>
            <str name="desc">This is an other product!</str></doc>
        </result>
      </lst>
      <lst>
        <str name="groupValue">faq</str>
        <result name="doclist" numFound="1" start="0">
          <doc>
            <str name="name">How to stuff</str>
            <str name="desc">This time: Simply do it!</str></doc>
        </result>
      </lst>
    </arr>
  </lst>
</lst>
</response>

我如何加入?

1 个答案:

答案 0 :(得分:1)

检查SOLR中的字段折叠功能

Result Grouping / Field Collapsing