忽略solr和太阳黑子的重音

时间:2014-02-27 14:52:54

标签: search solr ruby-on-rails-4 sunspot-rails

如果我搜索“agua”没有结果忽略搜索中的重音符号(á,ã,ç)?

#city数据库(id,name,uf,province_id)    1 Águas Clara PR 3 2 águas PR 4 3 Áraguaia PR 3

#schema.xml中

<fieldType name="text" class="solr.TextField" omitNorms="false">
  <analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StandardFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="15" />
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StandardFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

2 个答案:

答案 0 :(得分:5)

在过滤器链中使用ASCIIFoldingFilterFactory,用于索引和查询。使用您的示例:

 <fieldType name="text" class="solr.TextField" omitNorms="false">
  <analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StandardFilterFactory"/>
<filter class="solr.ASCIIFoldingFilterFactory" /> 
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="15" />
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.ASCIIFoldingFilterFactory" /> 
    <filter class="solr.StandardFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

答案 1 :(得分:0)

尝试运行分析以查看查询时和索引时发生的情况。

尝试类似的东西,调整主机,核心和字段名称:

http://localhost:8983/solr/core1/analysis/field?wt=json&analysis.showmatch=true&analysis.fieldvalue=%C3%A1guas&analysis.query=%C3%A1guas&analysis.fieldname=name

结果将显示如何在分析的所有步骤中处理您的查询字词

{
   responseHeader:{
      status:0,
      QTime:2
   },
   analysis:{
      field_types:{

      },
      field_names:{
         Noms:{
            index:[
               "org.apache.lucene.analysis.standard.StandardTokenizer",
               [
                  {
                     text:"état",
                     raw_bytes:"[c3 a9 74 61 74]",
                     start:0,
                     end:4,
                     type:"<ALPHANUM>",
                     position:1,
                     positionHistory:[
                        1
                     ]
                  }
               ],
               "org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilter",
               [
                  {
                     text:"etat",
                     raw_bytes:"[65 74 61 74]",
                     match:true,
                     position:1,
                     positionHistory:[
                        1,
                        1
                     ],
                     start:0,
                     end:4,
                     type:"<ALPHANUM>"
                  }
               ],
               "org.apache.lucene.analysis.core.StopFilter",
               [
                  {
                     text:"etat",
                     raw_bytes:"[65 74 61 74]",
                     match:true,
                     position:1,
                     positionHistory:[
                        1,
                        1,
                        1
                     ],
                     start:0,
                     end:4,
                     type:"<ALPHANUM>"
                  }
               ],
               "org.apache.lucene.analysis.core.LowerCaseFilter",
               [
                  {
                     text:"etat",
                     raw_bytes:"[65 74 61 74]",
                     match:true,
                     position:1,
                     positionHistory:[
                        1,
                        1,
                        1,
                        1
                     ],
                     start:0,
                     end:4,
                     type:"<ALPHANUM>"
                  }
               ]
            ],
            query:[
               "org.apache.lucene.analysis.standard.StandardTokenizer",
               [
                  {
                     text:"état",
                     raw_bytes:"[c3 a9 74 61 74]",
                     start:0,
                     end:4,
                     type:"<ALPHANUM>",
                     position:1,
                     positionHistory:[
                        1
                     ]
                  }
               ],
               "org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilter",
               [
                  {
                     text:"etat",
                     raw_bytes:"[65 74 61 74]",
                     position:1,
                     positionHistory:[
                        1,
                        1
                     ],
                     start:0,
                     end:4,
                     type:"<ALPHANUM>"
                  }
               ],
               "org.apache.lucene.analysis.synonym.SynonymFilter",
               [
                  {
                     text:"etat",
                     raw_bytes:"[65 74 61 74]",
                     org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength:1,
                     type:"<ALPHANUM>",
                     start:0,
                     end:4,
                     position:1,
                     positionHistory:[
                        1,
                        1,
                        1
                     ]
                  }
               ],
               "org.apache.lucene.analysis.core.StopFilter",
               [
                  {
                     text:"etat",
                     raw_bytes:"[65 74 61 74]",
                     position:1,
                     positionHistory:[
                        1,
                        1,
                        1,
                        1
                     ],
                     start:0,
                     end:4,
                     type:"<ALPHANUM>",
                     org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength:1
                  }
               ],
               "org.apache.lucene.analysis.core.LowerCaseFilter",
               [
                  {
                     text:"etat",
                     raw_bytes:"[65 74 61 74]",
                     position:1,
                     positionHistory:[
                        1,
                        1,
                        1,
                        1,
                        1
                     ],
                     start:0,
                     end:4,
                     type:"<ALPHANUM>",
                     org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength:1
                  }
               ]
            ]
         }
      }
   }
}