0

我尝试改进我项目中的拼写检查器行为。

我只对一个字段(“标题”)进行拼写检查。底部的相关配置。

此配置的原因 - 支持具有特殊字符的对象。

例如:
- 愤怒的战争:T70,世界上最好的坦克!
- 现代芯片组 M74K34#11$$1 - A:B:C - 100500bestprices!!!very-cool-object|title

为了涵盖大多数情况,我使用配置的“solr.WordDelimiterFilterFactory”过滤器。

问题:在拼写检查结果中:当我尝试搜索“愤怒的小鸟”时,我收到“愤怒的小鸟:”而不是预期的“愤怒的小鸟”。可能,只需按规范字符修剪关键字就足够了(我的意思是拆分“愤怒的战争:T70”,=>“愤怒”,“战争”,“T70”,“T”,“70”)。但是我如何通过规范字符修剪关键字?或者任何人有更好的想法?

<field name="title" type="text_en" indexed="true" stored="true" required="true" multiValued="false"/>

其中“text_en”是:

<fieldType name="text_en" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="0" catenateWords="1" catenateNumbers="0" catenateAll="0" splitOnCaseChange="0" splitOnNumerics="0" preserveOriginal="1"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.EnglishPossessiveFilterFactory"/>
    <filter class="solr.KStemFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="0" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="0" splitOnNumerics="0" preserveOriginal="1"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.EnglishPossessiveFilterFactory"/>
    <filter class="solr.KStemFilterFactory"/>
  </analyzer>
</fieldType>

在 SolrConfig 我使用

<requestHandler name="/select" class="solr.SearchHandler">
 <lst name="defaults">
   <str name="echoParams">explicit</str>
   <int name="rows">10</int>
   <str name="spellcheck.count">3</str>
   <str name="spellcheck.dictionary">default</str>
   <str name="spellcheck.dictionary">wordbreak</str> <!-- index -->

   <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">title</str>
  <!-- <str name="field">default_search_field</str> -->
  <str name="classname">solr.DirectSolrSpellChecker</str>
  <!-- the spellcheck distance measure used, the default is the internal levenshtein -->
  <!-- <str name="distanceMeasure">internal</str> -->
  <str name="distanceMeasure">org.apache.lucene.search.spell.JaroWinklerDistance</str>

  <!-- minimum accuracy needed to be considered a valid spellcheck suggestion -->
  <float name="accuracy">0.7</float>
  <!-- the maximum #edits we consider when enumerating terms: can be 1 or 2 -->
  <int name="maxEdits">2</int>
  <!-- the minimum shared prefix when enumerating terms -->
  <int name="minPrefix">1</int>
  <!-- maximum number of inspections per result. -->
  <int name="maxInspections">5</int>
  <!-- minimum length of a query term to be considered for correction -->
  <int name="minQueryLength">4</int>
  <!-- maximum threshold of documents a query term can appear to be considered for correction -->
  <float name="maxQueryFrequency">0.01</float>
  <!-- uncomment this to require suggestions to occur in 1% of the documents
    <float name="thresholdTokenFrequency">.01</float>
  -->      
  <str name="buildOnCommit">false</str>
  <str name="buildOnOptimize">true</str>
  <str name="combineWords">true</str>
  <str name="breakWords">true</str>
  <str name="comparatorClass">freq</str>
  <str name="collate">true</str>
  <str name="count">5</str>
</lst>

<lst name="spellchecker">
  <str name="name">wordbreak</str>
  <!-- <str name="classname">solr.DirectSolrSpellChecker</str> -->
  <str name="classname">solr.WordBreakSolrSpellChecker</str>
  <str name="field">title</str>
  <str name="combineWords">true</str>
  <str name="breakWords">true</str>
  <int name="maxChanges">5</int>
</lst>

</searchComponent>
4

1 回答 1

0

您可以控制要删除的字符

<filter class="solr.PatternReplaceFilterFactory" pattern="(:)" replacement=" " replace="all"/>
于 2013-10-11T17:09:22.643 回答