在 solr 8.1 中搜索子文档时,solr 仅在第一个结果中返回不需要的子文档
Solr 8.1 架构
<!-- Child doc fields -->
<field name="ChildCatalogItemId" type="plong" indexed="true" stored="true"/>
<field name="CatalogPriceSetItemListPriceId" type="plong" indexed="true" stored="true"/>
<field name="CatalogPriceSetId" type="plong" indexed="true" stored="true"/>
<field name="ListPriceEffectiveDate" type="pdate" indexed="true" stored="true"/>
<field name="PriceSetListPrice" type="pfloat" indexed="true" stored="true"/>
<field name="ChildCatalogId" type="plong" indexed="true" stored="true"/>
搜索查询
q = laptop
fl = *,[child parentFilter=laptop childFilter="ListPriceEffectiveDate:[* TO NOW]"]
XML 格式的 Solr 输出
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
<lst name="params">
<str name="q">laptop</str>
<str name="fl">*,[child parentFilter=laptop childFilter="ListPriceEffectiveDate:[* TO NOW]"]</str>
<str name="wt">xml</str>
<str name="_">1631084737005</str>
</lst>
</lst>
<result name="response" numFound="11" start="0">
<doc>
<date name="LastUpdatedDate">2021-05-28T10:37:48.553Z</date>
<str name="ProductName">HP Laptop 310</str>
<str name="PreferredSupplier">Hardware Supplier</str>
<str name="CatalogItemNumber">310</str>
<str name="id">76666</str>
<float name="ListPrice">88.0</float>
<long name="CatalogId">195</long>
<str name="CurrencyId">1</str>
<long name="CatalogItemId">76608</long>
<long name="SupplierId">159</long>
<long name="_version_">1710252893041328128</long>
<str name="_root_">76666</str>
<date name="timestamp">2021-09-07T14:17:38.653Z</date>
<doc>
<long name="ChildCatalogId">105</long>
<long name="CatalogPriceSetId">10</long>
<float name="PriceSetListPrice">77.0</float>
<long name="ChildCatalogItemId">75159</long> WRONG ITEM
<date name="ListPriceEffectiveDate">2021-05-28T00:00:00Z</date>
<long name="CatalogPriceSetItemListPriceId">13</long>
<str name="id">13</str>
<str name="_root_">75212</str>
<long name="_version_">1710252892830564352</long>
<str name="ManufacturerName">EMPTY</str>
<str name="ManufacturerNameAssigned">EMPTY</str>
<str name="DiversityClassification">EMPTY</str>
<date name="timestamp">2021-09-07T14:17:38.455Z</date>
</doc>
<doc>
<long name="ChildCatalogId">195</long>
<long name="CatalogPriceSetId">15</long>
<float name="PriceSetListPrice">88.0</float>
<long name="ChildCatalogItemId">76608</long> Correct Document
<date name="ListPriceEffectiveDate">2021-07-06T00:00:00Z</date>
<long name="CatalogPriceSetItemListPriceId">27</long>
<str name="id">27</str>
<str name="_root_">76666</str>
<long name="_version_">1710252893041328128</long>
<str name="ManufacturerName">EMPTY</str>
<str name="ManufacturerNameAssigned">EMPTY</str>
<str name="DiversityClassification">EMPTY</str>
<date name="timestamp">2021-09-07T14:17:38.653Z</date>
</doc>
</doc>
json响应
{
"responseHeader": {
"status": 0,
"QTime": 1,
"params": {
"q": "laptop",
"fl": "*,[child parentFilter=laptop childFilter=\"ListPriceEffectiveDate:[* TO NOW]\"]",
"wt": "json",
"_": "1631084737005"
}
},
"response": {
"numFound": 11,
"start": 0,
"docs": [
{
"LastUpdatedDate": "2021-05-28T10:37:48.553Z",
"ProductName": "HP Laptop 310",
"CatalogItemNumber": "310",
"id": "76666",
"ListPrice": 88.0,
"CatalogId": 195,
"CatalogItemId": 76608,
"_version_": 1710252893041328128,
"_root_": "76666",
"timestamp": "2021-09-07T14:17:38.653Z",
"_childDocuments_": [
{
"ChildCatalogId": 105,
"CatalogPriceSetId": 10,
"PriceSetListPrice": 77.0,
"ChildCatalogItemId": 75159,
"ListPriceEffectiveDate": "2021-05-28T00:00:00Z",
"CatalogPriceSetItemListPriceId": 13,
"id": "13",
"_root_": "75212",
"_version_": 1710252892830564352,
"ManufacturerName": "EMPTY",
"ManufacturerNameAssigned": "EMPTY",
"DiversityClassification": "EMPTY",
"timestamp": "2021-09-07T14:17:38.455Z"
},
{
"ChildCatalogId": 195,
"CatalogPriceSetId": 15,
"PriceSetListPrice": 88.0,
"ChildCatalogItemId": 76608,
"ListPriceEffectiveDate": "2021-07-06T00:00:00Z",
"CatalogPriceSetItemListPriceId": 27,
"id": "27",
"_root_": "76666",
"_version_": 1710252893041328128,
"ManufacturerName": "EMPTY",
"ManufacturerNameAssigned": "EMPTY",
"DiversityClassification": "EMPTY",
"timestamp": "2021-09-07T14:17:38.653Z"
}
]
}
问题
在上面的结果中,第一个 CHILD 文档是不需要的,solr 8.1 为同一目录中的另一个产品返回了结果。
笔记
我们没有使用这个网址中提到的嵌套路径- https://solr.apache.org/guide/8_1/indexing-nested-documents.html
此外,目录搜索工作正常,它返回特定项目的正确子文档。