3

我使用 solrj 作为客户端来索引 solr 服务器上的文档我是 solr 的新手,而且我在 solr 中突出显示有问题。用 solr 突出显示确切的短语不起作用。

例如,如果关键字是:“dulce hogar”,它会返回:

<i> dulce </i> <i> hogar </i> 

它应该是:

<i> dulce hogar </i> 

我不明白是哪个问题。

我在 schema.xml 中的配置

 <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"  />
    <!-- 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.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="1"/>
    <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

在 solrconfig.xml

 <requestHandler name="/select" class="solr.SearchHandler">

    <lst name="defaults">
  <str name="echoParams">explicit</str>
  <int name="rows">10</int>
   <str name="df">text</str>
  <bool name="hl.usePhraseHighlighter">true</bool>
</lst>


 </requestHandler>
<!-- Highlighting Component

   http://wiki.apache.org/solr/HighlightingParameters
-->
<searchComponent class="solr.HighlightComponent" name="highlight">
<highlighting>
  <!-- Configure the standard fragmenter -->
  <!-- This could most likely be commented out in the "default" case -->
  <fragmenter name="gap" 
              default="true"
              class="solr.highlight.GapFragmenter">
    <lst name="defaults">
      <int name="hl.fragsize">100</int>
    </lst>
  </fragmenter>

  <!-- A regular-expression-based fragmenter 
       (for sentence extraction) 
    -->
  <fragmenter name="regex" 
              class="solr.highlight.RegexFragmenter" default="true">
    <lst name="defaults">
      <!-- slightly smaller fragsizes work better because of slop -->
      <int name="hl.fragsize">70</int>
      <!-- allow 50% slop on fragment sizes -->
      <float name="hl.regex.slop">0.5</float>
      <!-- a basic sentence pattern -->
      <str name="hl.regex.pattern">[-\w ,/\n\&quot;&apos;]{20,200}</str>
      <bool name="hl.usePhraseHighlighter">true</bool>
      <bool name="hl.highlightMultiTerm">true</bool>
    </lst>
  </fragmenter>

  <!-- Configure the standard formatter -->
  <formatter name="html" 
             default="true"
             class="solr.highlight.HtmlFormatter">
    <lst name="defaults">
      <str name="hl.simple.pre"><![CDATA[<em>]]></str>
      <str name="hl.simple.post"><![CDATA[</em>]]></str>
    </lst>
  </formatter>

提前感谢您的帮助,

西尔。

4

2 回答 2

1

检查这篇文章。您需要设置 hl.q="dulce hogar" 字段以及 fastVector 以及phraseHighLighter。

于 2014-09-22T11:34:16.433 回答
0

我是 solr 的初学者,但我理解的是,要获得确切的短语,更喜欢使用 solr.NGramTokenizerFactory 而不是 WhitespaceTokenizerFactory 仅用于索引部分。或者您可以在您的请求中尝试突出显示选项hl.mergeContiguous=true(请参阅突出显示选项)。跳它可以帮助你。

于 2014-05-21T07:26:28.580 回答