Solr小写过滤器

Solr lower case filter

我正在尝试在 Solr 中制作拼写检查程序,但我遇到了大小写问题。问题是更改查询的大小写不会影响返回的结果数,但会更改拼写检查器的结果。例如,如果我键入 'leave',那么我会得到 7 个文档结果,但没有拼写检查结果。但是,如果我搜索 'Leave',那么我仍然会得到 7 个文档结果,但现在拼写检查有这些结果:

"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"]}]}

建议小写 'leave'。注意它仍然说 'correctlySpelled' 是真的。这是我的 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 中的停用词,并且我正在申请拼写字段类型,但如果我键入 'leave for application',它会建议将 'leave form application' 作为排序规则查询。为什么不删除停用词?

好的,我修好了。我将 solr 配置中基于索引的检查器更改为直接检查器,现在一切正常,即更改了这个

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

为此:

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

不确定为什么基于索引的会忽略过滤器,我必须查看文档。