我尝试使用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>
.. schema.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>
答案 0 :(得分:0)
我将令牌系统从WhiteSpaceTokenizerFactory
更改为NGramTokenizerFactory
并删除了NGramFilterFactory
- &gt;现在它(几乎)按预期工作了