Apache SOLR-建议程序在建议中省略了连字符和方括号

时间:2018-07-01 19:24:12

标签: solr

使用SOLR 7.1.3,我正在尝试实现一个提示器。 基本建议有效,但是索引中有一些特殊术语,如下所示:

[999-99-9]

现在,当我使用运行建议程序

q=myfield:[999-9*

我确实得到了建议,但是没有连字符和方括号。

sugggestions:[{ "term":"999 99 9" ...}]

我的期望是:

sugggestions:[{ "term":"[999-99-9]" ...}]

我如何告诉SOLR包含方括号和连字符?

这是我的建议者

<searchComponent name="suggest" class="solr.SuggestComponent">
    <lst name="suggester">
      <str name="name">mySuggester</str>
      <str name="lookupImpl">FreeTextLookupFactory</str>
      <str name="dictionaryImpl">DocumentDictionaryFactory</str>
      <str name="field">fulltext</str>
      <str name="ngrams">3</str>
      <float name="threshold">0.004</float>
      <str name="highlight">false</str>
      <str name="buildOnCommit">false</str>
      <str name="storeDir">mySuggester</str>
      <str name="separator"> </str>
      <str name="suggestFreeTextAnalyzerFieldType">text_general</str>
    </lst>
  </searchComponent>

我也尝试过此操作(不会返回任何结果):

<searchComponent name="suggest" class="solr.SuggestComponent">
  <lst name="suggester">
    <str name="name">infixSuggester</str>
    <str name="lookupImpl">AnalyzingInfixLookupFactory</str>
    <str name="dictionaryImpl">DocumentDictionaryFactory</str>
    <str name="field">fulltext</str>
    <str name="payloadField">fulltext</str>
    <str name="suggestAnalyzerFieldType">text_general</str>
  </lst>
</searchComponent>

[编辑]这是我的fieldType定义:

<fieldType name="myField" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
        <tokenizer class="solr.KeywordTokenizerFactory"/>
       <filter class="solr.PatternReplaceFilterFactory" pattern="'"
replacement="" replace="all" />

      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="solr.KeywordTokenizerFactory"/>
       <filter class="solr.PatternReplaceFilterFactory" pattern="'"
replacement="" replace="all" />

     <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>

1 个答案:

答案 0 :(得分:0)

所以,我知道了。

schema.xml

    <fieldType name="myField" class="solr.TextField" positionIncrementGap="100">
        <analyzer type="index">
            <tokenizer class="solr.ClassicTokenizerFactory"/>
            <filter class="solr.StandardFilterFactory"/>
            <filter class="solr.LowerCaseFilterFactory"/>
        </analyzer>
        <analyzer type="query">
            <tokenizer class="solr.ClassicTokenizerFactory"/>
            <filter class="solr.LowerCaseFilterFactory"/>
            <filter class="solr.TrimFilterFactory"/>
        </analyzer>
    </fieldType>

<field name="TheField" type="myField" multiValued="true" indexed="true" stored="true"/>

solrconfig.xml:

<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
    <lst name="defaults">
      <str name="suggest">true</str>
      <str name="suggest.count">10</str>
      <str name="suggest.dictionary">Suggester</str>
    </lst>
    <arr name="components">
      <str>suggest</str>
    </arr>
  </requestHandler>

<searchComponent name="suggest" class="solr.SuggestComponent">
  <lst name="suggester">
    <str name="name">Suggester</str>
    <str name="lookupImpl">FreeTextLookupFactory</str>
    <str name="dictionaryImpl">DocumentDictionaryFactory</str>
    <str name="field">TheField</str>
    <str name="storeDir">casSuggester</str>
    <str name="suggestFreeTextAnalyzerFieldType">myField</str>
  </lst>
</searchComponent>

它仍然不返回方括号,但是连字符在这里。