返回Solr 4.7

时间:2016-07-07 12:31:07

标签: 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>"
      ]**
    }
}

1 个答案:

答案 0 :(得分:3)

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

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

不会像文档所说的那样保留multiValue文档中的值顺序,但它也会以原始顺序返回多值文档的所有值。 因此,如果我们设置上面提到的参数,我们在索引中有以下文档:

{
        "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"
          ]**
        }
    }
相关问题