Request handle solrconfig.xml Spellchecker

时光毁灭记忆、已成空白 提交于 2019-12-30 03:29:04

问题


I am trying to set up spellchecker, according to solr documentation. But when I am testing, I don't have any suggestion. My piece of code follows:

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

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

    <lst name="spellchecker">
      <str name="classname">solr.IndexBasedSpellChecker</str>
      <str name="name">default</str>
      <str name="field">name</str>
      <str name="spellcheckIndexDir">./spellchecker</str>
    </lst>
    <str name="queryAnalyzerFieldType">textSpell</str>

  </searchComponent>


 <requestHandler name="/spellcheck" class="solr.SearchHandler">
    <lst name="defaults">
      <str name="echoParams">explicit</str>
      <!-- Optional, must match spell checker's name as defined above, defaults to "default" -->
      <str name="spellcheck.dictionary">default</str>
      <!-- omp = Only More Popular -->
      <str name="spellcheck.onlyMorePopular">false</str>
      <!-- exr = Extended Results -->
      <str name="spellcheck.extendedResults">false</str>
      <!--  The number of suggestions to return -->
      <str name="spellcheck.count">1</str>
    </lst>
    <arr name="last-components">
      <str>spellcheck</str>
    </arr>
  </requestHandler>

The query I send to Solr:
q=%2B%28text%3A%28gasal%29%29&suggestField=contentOriginal&ontologySeed=gasal&spellcheck.build=true&spellcheck.q=gasal&spellcheck=true&spellcheck.collate=true&hl=true&hl.snippets=5&hl.fl=text&hl.fl=text&rows=12&start=0&qt=%2Fsuggestprobabilistic

Does anybody know why?? Thanks in advance


回答1:


First, don't repeat queryAnalyzerFieldType twice in the component configuration.

It is recommended not to use a /spellcheck handler but instead to bind the spellcheck component to the standard query handler (or dismax if it is what you use) like this:

<requestHandler name="standard" class="solr.SearchHandler" default="true">
 <lst name="defaults">
    ...
 </lst>   
 <arr name="last-components">
    <str>spellcheck</str>
    ...         
 </arr>
</requestHandler>

You can then call it like this:
http://localhost:8983/solr/select?q=komputer&spellcheck=true

Also don't forget to build the spellcheck dictionary before you use it:
http://localhost:8983/solr/select/?q=*:*&spellcheck=true&spellcheck.build=true

You can force the dictionary to build at each commit by configuring it in the component:

<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
 <str name="queryAnalyzerFieldType">textSpell</str>
 <lst name="spellchecker">
  <str name="classname">solr.IndexBasedSpellChecker</str>
  <str name="name">default</str>
  <str name="field">name</str>
  <str name="spellcheckIndexDir">./spellchecker1</str>
  <str name="buildOnCommit">true</str>
 </lst>
</searchComponent>

Finally, make sure that your name field is really an indexed field of type textSpell and that it contains enough content to build a good dictionary. In my case, I have a field named spellchecker that is populated from a couple of fields of my index (using copyField instructions in the schema).



来源:https://stackoverflow.com/questions/3967101/request-handle-solrconfig-xml-spellchecker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!