如何让Solr建议者也能解决拼写错误?

时间:2014-05-26 14:36:12

标签: search solr autosuggest

我正在使用solr实现一个小型网络搜索引擎,并且我正在使用“建议者”组件 在查询表单中提供自动填充功能。

我可以从solr获得建议,但我也希望纠正拼写错误。 我问的问题与this question相同 但是我使用了不同的处理程序配置(在将最终查询提交到/ select之前,我将部分查询提交给单独的/建议请求处理程序)。

来自 SolrConfig.xml

<searchComponent class="solr.SpellCheckComponent" name="suggest">
<lst name="spellchecker">
  <str name="name">suggest</str>
<!--  <str name="classname">solr.DirectSolrSpellChecker</str> -->
  <str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
  <str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookupFactory</str>
  <str name="field">spelling</str>  <!-- all the other fields are copied here -->
  <float name="threshold">0.005</float>
  <str name="buildOnCommit">true</str>
</lst>
</searchComponent>

<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/suggest">
<lst name="defaults">
  <str name="suggest">true</str>
  <str name="suggest.count">10</str>
  <str name="spellcheck">true</str>
  <str name="spellcheck.extendedResults">true</str>
  <str name="spellcheck.dictionary">suggest</str>
  <!-- <str name="spellcheck.dictionary">default</str> -->
  <str name="spellcheck.onlyMorePopular">true</str>
  <str name="spellcheck.count">5</str>
  <str name="spellcheck.alternativeTermCount">5</str>
  <str name="spellcheck.maxResultsForSuggest">5</str>
  <str name="spellcheck.collate">true</str>
  <str name="spellcheck.maxCollations">5</str>      
</lst>
<arr name="components">
  <str>suggest</str>
 <!-- <str>spellcheck</str> enabling this gives me error: dictionary not found: suggest (same for "default")-->
</arr>
</requestHandler>`

将建议者组件的类名更改为directSolrSpellChecker会给我拼写检查但不会给出建议。

我怎样才能让建议者对拼写更正进行操作?

1 个答案:

答案 0 :(得分:0)

尝试使用thsi:

<!-- a spellchecker built from a field of the main index -->
<lst name="spellchecker">
  <str name="name">default</str>
  <str name="field">spelling</str>
  <str name="classname">solr.DirectSolrSpellChecker</str>
  <!-- the spellcheck distance measure used, the default is the internal levenshtein -->
  <str name="distanceMeasure">internal</str>
  <!-- minimum accuracy needed to be considered a valid spellcheck suggestion -->
  <float name="accuracy">0.5</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">2</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>
  -->
</lst>

  <requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
  <str name="df">spelling</str>
  <str name="spellcheck.dictionary">default</str>
  <str name="spellcheck.dictionary">wordbreak</str>
  <str name="spellcheck">on</str>
  <str name="spellcheck.extendedResults">true</str>       
  <str name="spellcheck.count">10</str>
  <str name="spellcheck.alternativeTermCount">5</str>
  <str name="spellcheck.maxResultsForSuggest">5</str>       
  <str name="spellcheck.collate">true</str>
  <str name="spellcheck.collateExtendedResults">true</str>  
  <str name="spellcheck.maxCollationTries">10</str>
  <str name="spellcheck.maxCollations">5</str>         
</lst>
<arr name="last-components">
  <str>spellcheck</str>
</arr>