Solr 6.1學習筆記 -- spellcheck 組件


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

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

    <!-- 下面的spellchecker使用了DirectSolrSpellChecker, 此類會使用主索引中的term進行拼寫檢查 -->
    <lst name="spellchecker">
      <str name="name">default</str>
      <str name="field">text</str>
      <str name="classname">solr.DirectSolrSpellChecker</str>
      <!-- spellcheck 使用的編輯距離(由一個詞轉化成另一個詞所做的變動), 默認值是 internal,用的是levenshtein metric-->
      <str name="distanceMeasure">internal</str>
<!-- 被認為是有效的 spellcheck suggestion的最小精度值,介於0和1之間的值。值越大,匹配的結果數越少。個人理解:假設對 cit進行拼寫檢查,
如果此值設置夠小的話,"fat","sit"都會被認為是"cit"的正確的拼寫。如果此值設置夠大,則"sit"會被認為是正確的拼寫
--> <float name="accuracy">0.5</float>
<!-- 值為 1 或者 2。指示最多有幾個字母變動。比如:對"manag"進行拼寫檢查,則會找到"manager"做為正確的拼寫;如果對"mana"進行
拼寫檢查,因為"mana"到"manager",需有3個字母的變動,所以"manager"會被遺棄
--> <int name="maxEdits">2</int>
<!-- 最小的前輟數。如設置為1,意思是指第一個字母不能錯。比如:輸入"cinner",雖然和"dinner"只有一個字母的編輯距離,
但是變動的是第一個字母,所以"dinner"不是"cinner"的正確拼寫
--> <int name="minPrefix">1</int> <!-- maximum number of inspections per result. --> <int name="maxInspections">5</int> <!-- 進行拼寫檢查所需要的最小的字母數。此處設置為4,表示如果只輸入了3個字母,則不會進行拼寫檢查(3個字母的單詞都會寫錯的話,我也無語了) --> <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> <!-- 被推薦的詞在文檔中出現的最小頻率。整數表示在文檔中出現的次數,百分比數表示有百分之多少的文檔出現了該推薦詞 <float name="thresholdTokenFrequency">.01</float> --> </lst> <!-- a spellchecker that can break or combine words. See "/spell" handler below for usage --> <lst name="spellchecker"> <str name="name">wordbreak</str> <str name="classname">solr.WordBreakSolrSpellChecker</str> <str name="field">text</str> <str name="combineWords">true</str> <str name="breakWords">true</str> <int name="maxChanges">10</int> </lst>

<!-- a spellchecker that use an alternate comparator comparatorClass be one of: 1. score (default) 2. freq (Frequency first, then score) 3. A fully qualified class name --> <!-- <lst name="spellchecker"> <str name="name">freq</str> <str name="field">lowerfilt</str> <str name="classname">solr.DirectSolrSpellChecker</str> <str name="comparatorClass">freq</str> --> </searchComponent> <!-- A request handler for demonstrating the spellcheck component. NOTE: This is purely as an example. The whole purpose of the SpellCheckComponent is to hook it into the request handler that handles your normal user queries so that a separate request is not needed to get suggestions. IN OTHER WORDS, THERE IS REALLY GOOD CHANCE THE SETUP BELOW IS NOT WHAT YOU WANT FOR YOUR PRODUCTION SYSTEM! See http://wiki.apache.org/solr/SpellCheckComponent for details on the request parameters. --> <requestHandler name="/spell" class="solr.SearchHandler" startup="lazy"> <lst name="defaults"> <!-- Solr will use suggestions from both the 'default' spellchecker and from the 'wordbreak' spellchecker and combine them. collations (re-written queries) can include a combination of corrections from both spellcheckers --> <str name="spellcheck.dictionary">default</str> <str name="spellcheck.dictionary">wordbreak</str> <str name="spellcheck">on</str>

<!-- 不僅返回建議詞在索引中的頻率,而且還返回原始的term在索引中的頻率 --> <str name="spellcheck.extendedResults">true</str> <str name="spellcheck.count">10</str>

<!-- 同時對多個單詞進行拼寫檢查時,每個單詞返回的建議詞的數量 --> <str name="spellcheck.alternativeTermCount">5</str>

   <!-- 當查詢的匹配結果超過maxResultsForSuggest設置的值時,則不再進行拼寫檢查。此處設置成5,是指
如果輸入"solr",假設能找到6條匹配的記錄,則不再對"solr"進行拼寫檢查 --> <str name="spellcheck.maxResultsForSuggest">5</str>
<!-- Solr會基於建議詞生成新的查詢以替換不正確的拼寫的查詢 -->
<str name="spellcheck.collate">true</str>

<!-- 意思與spellcheck.extendedResults相同,如果spellcheck.extendedResults設置為false,則此值將會被忽略 --> <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> </requestHandler>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM