【问题标题】:How to query Solr for child documents如何在 Solr 中查询子文档
【发布时间】:2016-12-04 05:17:23
【问题描述】:

我正在尝试运行块连接查询来提取子文档,但我收到“父查询产生的文档与父过滤器不匹配”错误。 我正在使用 Solr 5.5

我的架构如下所示:

<field name="url" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="name" type="text_en" indexed="true" stored="true" required="true" multiValued="false" />
<field name="content_type" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<uniqueKey>url</uniqueKey>

插入语句如下所示:

{
  "url": "http://www.test.com/index.html",
  "name": "parent product",
  "content_type": "parentDocument",
  "_childDocuments_": [
    {
      "url": "http://www.test.com/index2.html",
      "name": "child product",
      "content_type": "childDocument"
    },
    {
      "url": "http://www.test.com/index3.html",
      "name": "child product 2",
      "content_type": "childDocument"
    }
  ]
}

在控制台中运行标准 *:* 查询会拉回 3 个文档并显示子级属于其父级:

{
  "docs": [
    {
      "url": "http://www.test.com/index2.html",
      "name": "child product",
      "content_type": "childDocument",
      "_root_": "http://www.test.com/index.html"
    },
    {
      "url": "http://www.test.com/index3.html",
      "name": "child product 2",
      "content_type": "childDocument",
      "_root_": "http://www.test.com/index.html"
    },
    {
      "url": "http://www.test.com/index.html",
      "name": "test product",
      "content_type": "parentDocument",
      "_version_": 1541193313504198700,
      "_root_": "http://www.test.com/index.html"
    }
  ]
}

但是,如果我运行 q={!child of="content_type:parentDocument"},我会得到父文档,鉴于“child of”语句,我不会期望:

{
  "responseHeader": {
    "status": 0,
    "QTime": 0,
    "params": {
      "q": "{!child of=\"content_type:parentDocument\"}",
      "indent": "true",
      "wt": "json"
    }
  },
  "response": {
    "numFound": 1,
    "start": 0,
    "docs": [
      {
        "url": "http://www.test.com/index.html",
        "name": "test product",
        "content_type": "parentDocument",
        "_version_": 1541193313504198656,
        "_root_": "http://www.test.com/index.html"
      }
    ]
  }
}

但是,如果我添加任何类型的查询,我会收到错误,例如

q={!child of="content_type:parentDocument"}name:product 

甚至

q={!child of="content_type:parentDocument"}name:*

"父查询产生的文档与父过滤器不匹配,docID=0"

【问题讨论】:

    标签: solr


    【解决方案1】:

    因此,据我所知,查询无法返回子文档。它几乎就像一个查询和一个过滤器。查询,即name:* 可以匹配不允许的父子文档。我添加了一个额外的过滤器,即+name:product +content_type:parentDocument,以将结果限制为仅限父母。然后我添加了{!child of="content_type:parentDocument"} 来获取这些父母的孩子,所以我现在有了:

    {!child of="content_type:parentDocument"}+name:product +content_type:parentDocument
    

    这按预期工作。

    反之亦然:

    {!parent which="content_type:parentDocument"}+name:product +content_type:childDocument
    

    获取name:product的孩子家长

    【讨论】:

    猜你喜欢
    • 2017-03-22
    • 2016-04-23
    • 1970-01-01
    • 1970-01-01
    • 2020-07-21
    • 1970-01-01
    • 1970-01-01
    • 2016-08-10
    • 1970-01-01
    相关资源
    最近更新 更多