2016-07-07 42 views
0

我正在使用Solr 4.7在我的服务器上启用标准突出显示。我的文档包含以下字段(其他字段):返回突出显示的多值字段的所有相关值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

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

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