返回 Solr 4.7 中突出显示的多值字段的所有相关值

  • 本文关键字:字段 显示 Solr 返回 solr solrj
  • 更新时间 :
  • 英文 :


我正在努力使用 Solr 4.7 在我的服务器上启用标准突出显示。我的文档包含(以及其他)以下字段:

{
        "id": [
          "fdc3833a-0e4f-4314-ba8c"
        ],,
        "tag": [
          "solr",
          "solrJ",
          "solrCloud"
          "solrX"
        ],
        "title": "Solr question about highlighting",
        "description": "I am working to enable Standard Highlighting on my server with Solr 4.7. My documents contain (among the others) the following.........",
      }

在这三个字段中,只有"标签"是多值的。我在 solrconfig.xml 文件中的默认配置是:

<str name="hl">on</str>
<str name="hl.fl">content title description tag</str>
<str name="hl.snippets">2</str>

当我运行如下查询时:

https://<YOUR_PATH>/select?q=solr*&wt=json&indent=true

我得到以下亮点:

"highlighting": {
    "fdc3833a-0e4f-4314-ba8c": {
          "title": [
            "<b>Solr</b> question about highlighting"
          ],
          "summary": [
            "I am working to enable Standard Highlighting on my server with <b>Solr</b> 4.7. My documents contain (among the others) the following........."
          ],
          **"tag": [
            "<b>Solr</b>",
            "<b>SolrJ</b>"
          ]**
        }
}

虽然我希望获得所有标签。我发现 Solr 将多值字段中的多个值视为突出显示的片段,因此由于我有 hl.snippets=2,因此仅显示前两个值。如何获取标签的所有值?(显然,仅更改多值字段的代码段数量不是一个可接受的答案)。Solr 4.7 中有没有办法在突出显示中处理多值字段?

我的期望是得到这样的回应:

"highlighting": {
"fdc3833a-0e4f-4314-ba8c": {
      "title": [
        "<b>Solr</b> question about highlighting"
      ],
      "summary": [
        "I am working to enable Standard Highlighting on my server with <b>Solr</b> 4.7. My documents contain (among the others) the following........."
      ],
      **"tag": [
        "<b>Solr</b>",
        "<b>SolrJ</b>",
        "<b>SolrCloud</b>",
        "<b>SolrX</b>"
      ]**
    }
}

在搜索文档并运行一些测试后,我发现在 solrconfig.xml 中设置参数 hl.preserveMulti

<str name="hl.preserveMulti">true</str>

它不仅像文档所说的那样保留多值文档中的值顺序,而且还按原始顺序返回多值文档的所有值。因此,如果我们设置上面提到的参数,并且我们的索引中有以下文档:

{
        "id": [
          "fdc3833a-0e4f-4314-ba8c"
        ],,
        "tag": [
          "solr",
          "solrJ",
          "solrCloud"
          "solrX",
          "notRelevantTag"
        ],
        "title": "Solr question about highlighting",
        "description": "I am working to enable Standard Highlighting on my server with Solr 4.7. My documents contain (among the others) the following.........",
      }

查询:

https://<YOUR_PATH>/select?q=solr*&wt=json&indent=true

会给我一个突出显示的结果,如下所示:

"highlighting": {
    "fdc3833a-0e4f-4314-ba8c": {
          "title": [
            "<b>Solr</b> question about highlighting"
          ],
          "summary": [
            "I am working to enable Standard Highlighting on my server with <b>Solr</b> 4.7. My documents contain (among the others) the following........."
          ],
          **"tag": [
            "<b>Solr</b>",
            "<b>SolrJ</b>",
            "<b>SolrCloud</b>",
            "<b>SolrX</b>",
            "notRelevantTag"
          ]**
        }
    }

最新更新