Solr:LowerCaseFilterFactory未在SpellCheckComponent中应用

时间:2013-10-07 20:59:42

标签: solr spelling query-analyzer

我正在与Solr中的SpellCheckComponent进行斗争(使用solr 4.4和4.5进行测试)。我有一个字段类型定义如下:

<fieldtype name="termSuggest" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
    <tokenizer class="solr.WhitespaceTokenizerFactory" />
    <filter class="solr.LowerCaseFilterFactory" />
    <filter class="solr.PatternReplaceFilterFactory" pattern="(^[^A-Za-z0-9ÄÖÜßäöü]*|[^A-Za-z0-9ÄÖÜßäöü]*$)"
        replacement="" replace="all" />
    <filter class="solr.LengthFilterFactory" min="2" max="60" />
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_de.txt" format="snowball" />
    <filter class="solr.ShingleFilterFactory" maxShingleSize="3" outputUnigrams="true" outputUnigramsIfNoShingles="true" 
        tokenSeparator=" "/>
    <filter class="solr.RemoveDuplicatesTokenFilterFactory" />
</analyzer>
<analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory" />
    <filter class="solr.LowerCaseFilterFactory" />
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_de.txt" format="snowball" />
    <filter class="solr.ShingleFilterFactory" maxShingleSize="99" outputUnigrams="false" outputUnigramsIfNoShingles="true" 
        tokenSeparator=" "/> 
</analyzer>
</fieldtype>

使用solr管理分析器调查相应的字段,我可以看到,在索引和查询模式下正确分析了字段。特别是它是小写的。

但是,如果我在SpellCheckerComponent中使用此字段,我只会得到建议,如果该术语以小写形式提供(例如“bautrokner”正在工作,“Bautrokner”不是)。组件和请求处理程序的定义是在solr wiki中提供的(我知道拼写可能不是拼写纠正所必需的,但我也使用该字段进行自动建议 - 具有完全相同的问题):

<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
<!-- Multiple "Spell Checkers" can be declared and used by this component -->

<!-- a spellchecker built from a field of the main index -->
<lst name="spellchecker">
    <str name="name">default</str>
    <str name="field">_termsuggest</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.2</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">4</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>
</searchComponent>

<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
    <str name="df">_termsuggest</str>
    <str name="spellcheck.dictionary">default</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>
</requestHandler>

我已经搜索了几个小时的类似问题,但我找不到任何提示是什么问题。我希望由于查询分析器,查询字词应该是小写的。但事实似乎并非如此。

的Mathias

1 个答案:

答案 0 :(得分:0)

问题解决了:我错过了添加查询分析器字段类型:

<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
    <!-- Multiple "Spell Checkers" can be declared and used by this component -->
    <str name="queryAnalyzerFieldType">termSuggest</str>
...

如果没有指定queryAnalyzerFieldType,则使用简单的WhiteSpaceAnalyzer(https://issues.apache.org/jira/browse/SOLR-5111)。

的Mathias