Solr Spell检查正确返回误报Spelled()

时间:2016-07-17 03:49:00

标签: json xml solr solr5

我目前在本地服务器上使用solr 5x并使用Drupal实例生成所有索引。经过大量的配置后,我得到了一点,我对solr的实现非常满意。

然而,我刚才注意到的一个问题是正确的拼写仍被视为拼写错误,仍然会提供建议。

"correctlySpelled":false

正如您在 JSON输出中看到的那样,许可证车辆这两个字拼写正确且仍被归类为不正确

"spellcheck":{
   "suggestions":[
      "license",
      {
         "numFound":3,
         "startOffset":0,
         "endOffset":7,
         "suggestion":[
            "licensed",
            "licensee",
            "licenser"
         ]
      },
      "vehicle",
      {
         "numFound":3,
         "startOffset":8,
         "endOffset":15,
         "suggestion":[
            "chicle",
            "pedicle",
            "vehiculate"
         ]
      }
   ],
   "correctlySpelled":false,
   "collations":[
      "collation",
      "licensed chicle",
      "collation",
      "licensed pedicle",
      "collation",
      "licensed vehiculate",
      "collation",
      "licenser chicle",
      "collation",
      "licenser pedicle"
   ]
}

有没有人知道为什么会产生误报?

网址编码查询

http://192.168.33.10:8983/solr/drupal/spell?q=license+vehicle&spellcheck=true&spellcheck.accuracy=0.7&spellcheck.collate=true&defType=edismax&json.nl=flat&omitHeader=true&qf=ts_title^1&fl=*,score&start=0&fq=index_id:"new_index"&fq=hash:"96z3wm"&rows=10&wt=json&stopwords=true&lowercaseOperators=true

查询:

q = license+vehicle
spellcheck = true
spellcheck.accuracy = 0.7
spellcheck.collate = true
defType = edismax
json.nl = flat
omitHeader = true
qf = ts_title^1
fl = *,score
start = 0
fq = index_id:"new_index"
fq = hash:"96z3wm"
rows = 10
wt = json
stopwords = true
lowercaseOperators = true

schema.xml的相关部分:

<fieldType name="text" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <!-- <filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="15" /> -->
    <!-- in this example, we will only use synonyms at query time
    <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
    -->
    <!-- Case insensitive stop word removal. -->
    <filter class="solr.StopFilterFactory"
            ignoreCase="true"
            words="stopwords.txt"
            />
    <filter class="solr.WordDelimiterFilterFactory"
            protected="protwords.txt"
            generateWordParts="1"
            generateNumberParts="1"
            catenateWords="1"
            catenateNumbers="1"
            catenateAll="0"
            splitOnCaseChange="0"
            preserveOriginal="1"/>
    <filter class="solr.LengthFilterFactory" min="2" max="100" />
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.SnowballPorterFilterFactory" language="English" protected="protwords.txt"/>
    <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <!-- <filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="15" /> -->

  <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.StopFilterFactory"
            ignoreCase="true"
            words="stopwords.txt"
            />
    <filter class="solr.WordDelimiterFilterFactory"
            protected="protwords.txt"
            generateWordParts="1"
            generateNumberParts="1"
            catenateWords="0"
            catenateNumbers="0"
            catenateAll="0"
            splitOnCaseChange="0"
            preserveOriginal="1"/>
    <filter class="solr.LengthFilterFactory" min="2" max="100" />
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.SnowballPorterFilterFactory" language="English" protected="protwords.txt"/>
    <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
  </analyzer>
  <analyzer type="multiterm">
    <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <!-- <filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="15" /> -->

    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.StopFilterFactory"
            ignoreCase="true"
            words="stopwords.txt"
            />
    <filter class="solr.WordDelimiterFilterFactory"
            protected="protwords.txt"
            generateWordParts="1"
            generateNumberParts="1"
            catenateWords="0"
            catenateNumbers="0"
            catenateAll="0"
            splitOnCaseChange="1"
            preserveOriginal="1"/>
    <filter class="solr.LengthFilterFactory" min="2" max="100" />
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.SnowballPorterFilterFactory" language="English" protected="protwords.txt"/>
    <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
  </analyzer>
</fieldType>

solrconfig.xml的相关部分

  <requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
    <lst name="defaults">
      <str name="df">spell</str> <!--The default field for spell checking. -->
      <str name="spellcheck.dictionary">file</str> <!--default or file or jarowinkler as mentioned above. -->
      <str name="spellcheck">on</str>
      <str name="spellcheck.extendedResults">true</str>
      <str name="spellcheck.count">3</str>
      <str name="spellcheck.maxResultsForSuggest">5</str>
      <str name="spellcheck.collate">false</str>
      <str name="spellcheck.collateExtendedResults">false</str>
      <str name="spellcheck.maxCollationTries">10</str>
      <str name="spellcheck.maxCollations">5</str>
    </lst>
    <arr name="last-components">
      <str>spellcheck</str>
    </arr>
  </requestHandler>

  <searchComponent name="spellcheck" class="solr.SpellCheckComponent">

    <str name="queryAnalyzerFieldType">textSpell</str>

    <lst name="spellchecker">
      <str name="name">default</str>
      <str name="field">spell</str>
      <str name="spellcheckIndexDir">spellchecker</str>
      <str name="buildOnOptimize">true</str>
    </lst>

    <lst name="spellchecker">
      <str name="classname">solr.FileBasedSpellChecker</str>
      <str name="name">file</str>
      <str name="sourceLocation">spellings.txt</str>
      <str name="characterEncoding">UTF-8</str>
      <str name="spellcheckIndexDir">spellcheckerFile</str>
    </lst>

  </searchComponent>

1 个答案:

答案 0 :(得分:0)

这也是我与Solr一起经历的事情。它以不可预测的方式发生。我用来避免这种情况的方法是使用edismax参数“mm”进行拼写预检,方法是将其设置为100。尝试在edismax查询中设置mm = 100,看看是否有效。然后你制作一个流程,你的第一个严格的拼写检查单词,然后传递给搜索查询处理程序。如果指定mm = 100,请不要在任何类型的双引号中传递您的短语,只需按原样传递即可。如果有帮助,请告诉我:)。