2016-11-07 68 views
0

我想在Solr中製作拼寫檢查程序,並且遇到了案例問題。問題在於改變查詢的情況並不影響返回結果的數量,但它改變了拼寫檢查結果。例如,如果我輸入'leave',那麼我會得到7個文檔結果並且沒有拼寫檢查結果。但是,如果我搜索「離開」,那麼我仍然得到7分文件的結果,但現在拼寫檢查有以下結果:Solr小寫過濾器

"spellcheck":{ 
"suggestions":[ 
    "Leave",{ 
    "numFound":3, 
    "startOffset":0, 
    "endOffset":5, 
    "origFreq":0, 
    "suggestion":[{ 
     "word":"leave", 
     "freq":7}, 
     { 
     "word":"lease", 
     "freq":4}, 
     { 
     "word":"travel", 
     "freq":2}]}], 
"correctlySpelled":true, 
"collations":[ 
    "collation",{ 
    "collationQuery":"leave", 
    "hits":7, 
    "misspellingsAndCorrections":[ 
     "Leave","leave"]}]} 

暗示小寫的「假」。請注意,它仍然表示'correctSpelled'是真實的。下面是從我的schema.xml中的字段和字段類型:

<field name="title"   type="text_en" indexed="true" stored="true" multiValued="false" /> 
<field name="filename"  type="string" indexed="true" stored="true" multiValued="false" /> 
<field name="filext"  type="string" indexed="true" stored="true" multiValued="false" /> 
<field name="version"  type="int"  indexed="false" stored="true" multiValued="false" /> 
<field name="docSet"  type="string" indexed="true" stored="true" multiValued="false" /> 
<field name="businessArea" type="string" indexed="true" stored="true" multiValued="false" /> 
<field name="processGroup" type="string" indexed="true" stored="true" multiValued="false" /> 
<field name="applicability" type="string" indexed="true" stored="true" multiValued="true" /> 
<field name="content"  type="text_en" indexed="true" stored="true" multiValued="false" /> 
<field name="lastIndex"  type="int"  indexed="true" stored="true" multiValued="false" /> 
<field name="popularity" type="int"  indexed="true" stored="true" multiValued="false" default="1"/> 

<field name="speller" type="speller_type" indexed="true" stored="true" multiValued="true" /> 

<copyField source="*" dest="speller"/> 

<fieldType name="speller_type" class="solr.TextField" positionIncrementGap="100"> 
    <analyzer type="index"> 
    <tokenizer class="solr.StandardTokenizerFactory"/> 
    <filter class="solr.LowerCaseFilterFactory"/> 
    <filter class="solr.StopFilterFactory" 
      ignoreCase="true" 
      words="stopwords_en.txt"/> 
    </analyzer> 

    <analyzer type="query"> 
    <tokenizer class="solr.StandardTokenizerFactory"/> 
    <filter class="solr.LowerCaseFilterFactory"/> 
    <filter class="solr.StopFilterFactory" 
      ignoreCase="true" 
      words="stopwords_en.txt"/> 
    </analyzer> 
</fieldType> 

這是我solrconfig.xml中的拼寫檢查部位:

<requestHandler name="/select" class="solr.SearchHandler"> 
    <lst name="defaults"> 

    ... 

    <!--**************************************************************** 
    * Spellcheck configuration 
    *****************************************************************--> 
    <str name="spellcheck">on</str> 
    <!-- Suggestions --> 
    <str name="spellcheck.count">10</str> 
    <!-- <str name="spellcheck.maxResultsForSuggest">10</str> --> 
    <str name="spellcheck.extendedResults">true</str> 
    <!-- Collations --> 
    <str name="spellcheck.collate">true</str> 
    <str name="spellcheck.maxCollationTries">5</str> 
    <str name="spellcheck.collateExtendedResults">true</str> 
    <str name="spellcheck.collateMaxCollectDocs">0</str> 

    ... 

    </lst> 

    <arr name="last-components"> 
    <str>spellcheck</str> 
    </arr> 
</requestHandler> 


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

如果我申請一個較低的情況下,過濾器的拼寫字段,那麼爲什麼要在搜索時更改案例以更改拼寫檢查程序的結果?我一直在尋找解決方案,但找不到任何修復它的方法。

感謝您的任何幫助。

編輯:我遇到了與停用詞相同的問題,它們沒有被應用。即使'for'是stopwords.txt中的一個停用詞,並且我正在應用到拼寫器fieldType,但如果鍵入'leave for application',它會建議'離開表單應用程序'作爲歸類查詢。爲什麼停止詞被刪除?

回答

0

好吧我修好了。我改變了基於索引的檢查在Solr的配置,以直接之一,現在一切工作正常,即改變了這種

<str name="classname">solr.IndexBasedSpellChecker</str> 
<str name="spellcheckIndexDir">./spellchecker</str> 

要這樣:

<str name="classname">solr.DirectSolrSpellChecker</str> 

不知道爲什麼基於一個指標忽略了過濾器,我將不得不查看文檔。