Solr - 突出显示查询短语

时间:2011-11-29 09:55:31

标签: solr lucene solrj solandra

是否可以突出显示整个查询字词? F.E.当我要求“美国”时,我想得到:

<em>United States</em>

而不是:

<em>United</em> <em>States</em>

我在整个互联网上搜索了一个答案,使用了 hl.mergeContiguous hl.usePhrasesHighlighter hl.highlightMultiTerm 的所有组合参数仍然无法使其发挥作用。

我的查询是:

http://localhost:8983/solandra/idxPosts.proj350_139/select?q=post_text:"Janusz Palikot"&hl=true&hl.fl=post_text&hl.mergeContiguous=true&hl.usePhrasesHighlighter=true&hl.highlightMultiTerm=true

答案是:

...
<arr name="post_text"><str>Tag: <em>janusz</em> <em>palikot</em> - Sowiniec: "Sowiniec"</str></arr>
...

我的“post_text”字段是:

<field name="post_text" type="text" indexed="true" stored="true" termVectors="true" termPositions="true" termOffsets="true" required="true" />

我的“文字”类型是:

<fieldType name="text" class="solr.TextField">
    <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory" />
        <filter class="solr.TrimFilterFactory" />
        <filter class="solr.LowerCaseFilterFactory" />
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords_pl.txt" />
        <filter class="solr.ReversedWildcardFilterFactory" />
    </analyzer>
    <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory" />
        <filter class="solr.TrimFilterFactory" />
        <filter class="solr.LowerCaseFilterFactory" />
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords_pl.txt" />
    </analyzer>
</fieldType>

我还尝试将 FastVectorHighlighter hl.useFastVectorHighlighter = true 一起使用但遇到错误:

Problem accessing /solandra/idxPosts.proj350_139/select. Reason:

    -6

java.lang.ArrayIndexOutOfBoundsException: -6
    at lucandra.TermFreqVector.getOffsets(TermFreqVector.java:224)
    at org.apache.lucene.search.vectorhighlight.FieldTermStack.<init>(FieldTermStack.java:100)
    at org.apache.lucene.search.vectorhighlight.FastVectorHighlighter.getFieldFragList(FastVectorHighlighter.java:175)
    at org.apache.lucene.search.vectorhighlight.FastVectorHighlighter.getBestFragments(FastVectorHighlighter.java:166)
    at org.apache.solr.highlight.DefaultSolrHighlighter.doHighlightingByFastVectorHighlighter(DefaultSolrHighlighter.java:509)
    at org.apache.solr.highlight.DefaultSolrHighlighter.doHighlighting(DefaultSolrHighlighter.java:376)
    at org.apache.solr.handler.component.HighlightComponent.process(HighlightComponent.java:116)
    at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:194)
    ...

请帮帮我吗?

2 个答案:

答案 0 :(得分:7)

对于短语高亮显示,有一个Jira静止等待通过Solr代码。

答案 1 :(得分:-1)

为此选择solr doc,有参数hl,设置为真。