Solr分组结果

时间:2018-04-02 15:15:23

标签: solr solrj solrcloud solr-query-syntax

所以我有一个带有以下JSON的solr结果:

{
  "grouped": {
    "manu_exact": {
      "matches": 2,
      "groups": [
        {
          "groupValue": "SOLR1000",
          "doclist": {
            "numFound": 2,
            "start": 0,
            "docs": [
              {
                "id": "SOLR1000",
                "name": "Solr, the Enterprise Search Server",
                "date":"March 1, 2018 03:00:00",
                "status":"Cancel"
              },
              {
               "id": "SOLR1000",
                "name": "Solr, the Enterprise Search Server",
                "date":"March 1, 2018 01:00:00",
                "status":"New"
              }

            ]
          }
        },
        {
          "groupValue": "VS1GB400C3",
          "doclist": {
            "numFound": 2,
            "start": 0,
            "docs": [
              {
                "id": "VS1GB400C3",
                "name": "Retail",
                "date":"March 4, 2018 04:00:00",
                "status":"Shipped"
              },
              {
                "id": "VS1GB400C3",
                "name": "Retail",
                "date":"March 4, 2018 02:00:00",
                "status":"New"
              }
            ]
          }
        }
      ]
    }
  }
}

相关字段的字段定义为:

<field name="id" type="string" indexed="true" stored="true" required="true" /> 
<field name="date" type="tdate" indexed="true" stored="true"/>
<field name="status" type="string" indexed="true" stored="true"/>

&#34;字符串&#34;的字段类型和&#34; tdate&#34;类型如下:

<fieldType name="string" class="solr.StrField"
      positionIncrementGap="100"/></fieldType>
<fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" 
      positionIncrementGap="0"/></fieldType>

上述查询由以下分组参数生成:

的圈子=真安培; group.field = ID&安培; group.sort = date desc&amp; group.limit = 10

我希望做到以下几点:

运行一个查询,其中仅包含那些包含未被取消&#34;的文档的组。

基本上,排序组给出了产品状态的时间线。我只想检索那些没有最新状态的文件&#34;取消&#34;。

这是通过按日期字段对组进行排序并检查第一个文档的状态来完成的。

在上面的示例中,我不想包含第一个组,因为其最新文档的状态字段具有值:&#34;取消&#34;。

但是我想要包含第二组,因为其最新文档的状态字段具有值:&#34;已发货&#34;而不是&#34;取消&#34;。

任何想法如何做到这一点?

非常感谢任何帮助。

0 个答案:

没有答案
相关问题