我尝试使用 SOLR 4.4 的高亮功能。经过一番尝试,它终于奏效了,但不像我预期的那样:
Generell 设置:我有一个文本和一个标题字段。两者都被索引和搜索,但仅在标题字段中需要突出显示。
- 第一次尝试:文档的标题字段设置为
string
=> 没有突出显示结果,即使该字段已存储 - 第二次尝试:将字段更改为
text_ws
(仅WhiteSpace-Tokenizer
)。我不太确定是否必须进入index
标题字段,所以我做到了。=> HL 有效,但仅适用于直接匹配(q=Apple 在标题中没有 HL Apple-Pie - q=Apple-Pie 有) - 第三次尝试:添加
ngram
到标题字段。现在 q:apple 会成功,但会突出显示完整的 Apple-pie,而不仅仅是查询词。
现在的问题是:是预期的行为还是有办法只突出显示查询词
编辑:片段为..
.. solrconfig.xml
<requestHandler name="/query" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="wt">json</str>
<str name="indent">true</str>
<str name="df">text</str>
<str name="defType">edismax</str>
<str name="qf">title, text</str>
<str name="hl">true</str>
<str name="hl.fl">title</str>
<str name="hl.simple.pre"><b class="text-success"></str>
<str name="hl.simple.post"></b></str>
</lst>
</requestHandler>
.. 架构.xml
<fieldType name="text" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<charFilter class="solr.HTMLStripCharFilterFactory" />
<tokenizer class="solr.WhitespaceTokenizerFactory" />
<filter class="solr.WordDelimiterFilterFactory" stemEnglishPossessive="0" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="0" preserveOriginal="1" />
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
<filter class="solr.LowerCaseFilterFactory" />
<filter class="solr.SnowballPorterFilterFactory" language="German" />
<filter class="solr.RemoveDuplicatesTokenFilterFactory" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory" />
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="0" preserveOriginal="1" />
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
<filter class="solr.LowerCaseFilterFactory" />
<filter class="solr.SnowballPorterFilterFactory" language="German" />
<filter class="solr.RemoveDuplicatesTokenFilterFactory" />
</analyzer>
</fieldType>
<fieldType name="text_ngrammed" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<charFilter class="solr.HTMLStripCharFilterFactory" />
<tokenizer class="solr.WhitespaceTokenizerFactory" />
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
<filter class="solr.LowerCaseFilterFactory" />
<filter class="solr.NGramFilterFactory" minGramSize="3" maxGramSize="10" />
<filter class="solr.RemoveDuplicatesTokenFilterFactory" />
<!-- <filter class="solr.SnowballPorterFilterFactory" language="English" protected="protwords.txt"/> -->
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
<fields>
<!-- IDs -->
<field name="id" type="string" indexed="true" stored="true" required="true" />
<!-- Content -->
<field name="title" type="text_ngrammed" indexed="true" stored="true" termVectors="true" termPositions="true" termOffsets="true" />
<field name="text" type="text" indexed="true" stored="false" multiValued="true" />
</fields>