Solr-Highlight:意外结果

时间:2013-10-28 09:53:02

标签: solr highlighting

我尝试使用SOLR 4.4的突出显示功能。经过一番尝试后,它终于有效了,但并不像我预期的那样:

Generell设置:我有一个文本和一个标题字段。两者都被索引和搜索,但只在标题字段中需要突出显示。

  • 第一次尝试:文档的标题字段设置为string =>即使存储了字段,也没有突出显示结果
  • 第二次尝试:将字段更改为text_ws(仅WhiteSpace-Tokenizer)。我不太确定我是否必须index标题字段,所以我做到了。 => HL工作,但仅用于直接匹配(q = Apple在标题中没有HL Apple-Pie - q = Apple-Pie确实如此)
  • 第3次尝试:将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">&lt;b class="text-success"&gt;</str>
        <str name="hl.simple.post">&lt;/b&gt;</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>

1 个答案:

答案 0 :(得分:0)

我将令牌系统从WhiteSpaceTokenizerFactory更改为NGramTokenizerFactory并删除了NGramFilterFactory - &gt;现在它(几乎)按预期工作了