2014-09-19 128 views
3

A我需要执行短语搜索。在搜索结果即时得到确切的短语匹配的,但看到高亮部分我看到这句话是记号化,即这是我所得到的,当我搜索prase“1天”:Solr:如何突出显示整个搜索短语?

<arr name="post"> 
    <str><em>Day</em> <em>1</em> We have begun a new adventure! An early morning (4:30 a.m.) has found me meeting with</str> 
</arr> 

这是什么我想收到的结果:

<arr name="post"> 
    <str><em>Day 1</em> We have begun a new adventure! An early morning (4:30 a.m.) has found me meeting with</str> 
</arr> 

我在做查询是这样的: 管理控制台:

q = day 1 
fq = post:"day 1" OR title:"day 1" 
hl = true 
hl.fl =title,post 

选择Q =天+ 1 & FQ =交%3A%22天+ 1%22 + OR +标题%3A%22天+ 1%22 &重量= XML &缩进=真& HL =真& hl.fl =标题%2Cpost & hl.simple.pre =%3Cem%3E & hl.simple.post =%3C%2Fem%3E

Theese是我的字段:

 <field name="post" type="text_general" indexed="true" stored="true" required="true" multiValued="false" /> 
     <field name="post" type="text_general" indexed="true" stored="true" required="true" multiValued="false" /> 

这是Solr模式部分我fied type text_general:

<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100"> 
    <analyzer type="index"> 
    <tokenizer class="solr.WhitespaceTokenizerFactory"/> 
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" /> 

    <!-- in this example, we will only use synonyms at query time 
    <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/> 
    --> 
    <filter class="solr.LowerCaseFilterFactory"/> 
    </analyzer> 
    <analyzer type="query"> 
    <tokenizer class="solr.WhitespaceTokenizerFactory"/> 
    <filter class="solr.GreekStemFilterFactory"/> 
    <filter class="solr.GreekLowerCaseFilterFactory"/> 
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" /> 
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/> 
    <filter class="solr.LowerCaseFilterFactory"/> 
    </analyzer> 
</fieldType> 

B)我可以在突出显示部分看到更令人不安的结果,即突出显示不是预期的整个单词,而是单个片段:.where you get to see all of Athens ... <em>Day</em> 2 - Carmens 我不想在突出显示的部分中看到此结果(只需要看到“Day 1" )。有任何想法吗 ?

我读了Solr的高光部分,但..真的......甚至没有一个例子!

+1

我有点被你的帖子的最后一节混淆。在开始时你写道,你只收到第1天的回复,而最后你写了你收到另一个回复。哪一个? – 2014-09-21 22:29:00

+0

所有的文档都包含“第1天”,但在某些情况下,现场文章可以=“第1天,我做了这个和那个......第2天,我做了其他的事情......”。我确定在文档部分中,结果至少有一句“第1天”。 '回复'有两种口味:文件和这些文件的亮点版本。 – 2014-09-22 05:57:09

回答

6

了需要插入的参数是hl.q这基本上意味着“我想这句话加以强调”和hl.usePhraseHighlighter =真实hl.useFastVectorHighlighter =真

所以通过添加到我原来的查询:&hl.q="Day+1"&hl.usePhraseHighlighter=true&hl.useFastVectorHighlighter=true工作。对于B)

我将fq = post:"day 1" OR title:"day 1"更改为fq = post:"day 1"。我知道后者从我所需要的无所作为的工作中减少了。使用该

fastVectorHighliter配置:

<field name="post" type="text_general" indexed="true" stored="true" required="true" multiValued="false" termVectors="true" termPositions="true" termOffsets="true"/> 
1

看着docs我找到了一个选项,可以加入彼此相邻的元素。

的选项hl.mergeContiguous

+2

有很多关于同一个问题的帖子,这个参数没有起作用,而且针头说这个试验并没有工作。例如http://stackoverflow.com/questions/16700916/solr-highlighting-every-word-individually-for-a-phrase-query – 2014-09-22 06:00:20