2011-06-18 74 views

回答

2

从Solr的维基, 将以下部分添加到您的solrconfig.xml中

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

    <lst name="spellchecker"> 
     <!-- 
      Optional, it is required when more than one spellchecker is configured. 
      Select non-default name with spellcheck.dictionary in request handler. 
     --> 
     <str name="name">default</str> 
     <!-- The classname is optional, defaults to IndexBasedSpellChecker --> 
     <str name="classname">solr.IndexBasedSpellChecker</str> 
     <!-- 
       Load tokens from the following field for spell checking, 
       analyzer for the field's type as defined in schema.xml are used 
     --> 
     <str name="field">spell</str> 
     <!-- Optional, by default use in-memory index (RAMDirectory) --> 
     <str name="spellcheckIndexDir">./spellchecker</str> 
     <!-- Set the accuracy (float) to be used for the suggestions. Default is 0.5 --> 
     <str name="accuracy">0.7</str> 
     <!-- Require terms to occur in 1/100th of 1% of documents in order to be included in the dictionary --> 
     <float name="thresholdTokenFrequency">.0001</float> 
    </lst> 
    <!-- Example of using different distance measure --> 
    <lst name="spellchecker"> 
     <str name="name">jarowinkler</str> 
     <str name="field">lowerfilt</str> 
     <!-- Use a different Distance Measure --> 
     <str name="distanceMeasure">org.apache.lucene.search.spell.JaroWinklerDistance</str> 
     <str name="spellcheckIndexDir">./spellchecker</str> 

    </lst> 

    <!-- This field type's analyzer is used by the QueryConverter to tokenize the value for "q" parameter --> 
    <str name="queryAnalyzerFieldType">textSpell</str> 
</searchComponent> 
<!-- 
    The SpellingQueryConverter to convert raw (CommonParams.Q) queries into tokens. Uses a simple regular expression 
    to strip off field markup, boosts, ranges, etc. but it is not guaranteed to match an exact parse from the query parser. 

    Optional, defaults to solr.SpellingQueryConverter 
--> 
<queryConverter name="queryConverter" class="solr.SpellingQueryConverter"/> 

<!-- Add to a RequestHandler 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
NOTE: YOU LIKELY DO NOT WANT A SEPARATE REQUEST HANDLER FOR THIS COMPONENT. THIS IS DONE HERE SOLELY FOR 
THE SIMPLICITY OF THE EXAMPLE. YOU WILL LIKELY WANT TO BIND THE COMPONENT TO THE /select STANDARD REQUEST HANDLER. 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
--> 


<requestHandler name="/spellCheckCompRH" class="solr.SearchHandler"> 
    <lst name="defaults"> 
     <!-- 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> 
<!-- Add to a RequestHandler 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
REPEAT NOTE: YOU LIKELY DO NOT WANT A SEPARATE REQUEST HANDLER FOR THIS COMPONENT. THIS IS DONE HERE SOLELY FOR 
THE SIMPLICITY OF THE EXAMPLE. YOU WILL LIKELY WANT TO BIND THE COMPONENT TO THE /select STANDARD REQUEST HANDLER. 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
--> 
    <arr name="last-components"> 
     <str>spellcheck</str> 
    </arr> 
    </requestHandler> 

这个配置加样在这之后,你可以要求建立拼写检查指标

http://localhost:8983/solr/spell?q=some query&spellcheck=true&spellcheck.collate=true&spellcheck.build=true 

注意不包括在每次请求中查询的最后一部分,因为此次编译索引在您请求的所有时间都会生成拼写索引 先前在第一次请求后变为

http://localhost:8983/solr/spell?q=some query&spellcheck=true&spellcheck.collate=true 

在前面的XML sextion son't忘记以取代上要建立自己的拼写检查对

场场法术现在你可以感受到拼写检查

+0

这样的力量我收到了拼写检查词典。但我没有得到如何将它包含在我的搜索结果中。我的意思是在jsp页面中显示serach结果,我解析了一个json对象。包括splellchecker应该是什么我的网址 – Romi

+0

确保您已添加: 拼写检查 到您的默认查询结果处理程序,以便有拼写检查上运行选择。 – lindstromhenrik

+0

@lindstromhenrik:我的 spellcheck在我的请求处理程序中。但我没有得到请告诉我为什么这样? – Romi