首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >返回Solr 4.7突出显示的多值字段的所有相关值

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

Stack Overflow用户
提问于 2016-07-07 12:31:07
回答 1查看 1.1K关注 0票数 1

我正在使用Solr4.7在我的服务器上启用标准高亮显示。我的文件(除其他外)包括下列字段:

代码语言:javascript
复制
{
        "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文件中的默认配置是:

代码语言:javascript
复制
<str name="hl">on</str>
<str name="hl.fl">content title description tag</str>
<str name="hl.snippets">2</str>

当我运行这样的查询时:

代码语言:javascript
复制
https://<YOUR_PATH>/select?q=solr*&wt=json&indent=true

我有以下要点:

代码语言:javascript
复制
"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中是否有一种在突出显示中处理多值字段的方法?

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

代码语言:javascript
复制
"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>"
      ]**
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-07 12:31:07

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

代码语言:javascript
复制
<str name="hl.preserveMulti">true</str>

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

代码语言:javascript
复制
{
        "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.........",
      }

查询:

代码语言:javascript
复制
https://<YOUR_PATH>/select?q=solr*&wt=json&indent=true

将给我一个突出的结果如下:

代码语言:javascript
复制
"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"
          ]**
        }
    }
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38245547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档