Solr:使用带有高级solr模式的拼写检查程序

时间:2013-10-11 16:21:49

标签: solr

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

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

如果这个配置的原因 - 支持具有特殊字符的对象。

e.g。 :
  - 愤怒的战争:T70,世界上最好的坦克!   - 现代芯片组M74K34#11 $$ 1   - 答:B:C   - 100500bestprices !!!非常酷的对象|标题

涵盖我使用已配置的大多数情况" solr.WordDelimiterFilterFactory"过滤

问题:在拼写检查结果中:当我尝试搜索" angr birds"我收到了愤怒的小鸟:"反而期待"愤怒的小鸟"。可能,只需通过spec chars修剪关键字(我的意思是分裂"愤怒的战争:T70," =>"愤怒","战争", " T70"," T"," 70")。但我如何通过spec chars修剪关键字?或者任何人都有更好的想法?

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

其中&#34; text_en&#34;是:

<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>

1 个答案:

答案 0 :(得分:0)

您可以控制要删除的字符

<filter class="solr.PatternReplaceFilterFactory" pattern="(:)" replacement=" " replace="all"/>