默认情况下 Apache Solr 是不支持中文检索的,如果文档中包含中文,必须用完整的一句中文才能检索出内容。
下面以 Apache Solr 的演示程序为例,注意:粗体部分是需要修改的地方。
找到如下三行:
     <fieldType name=”text” class=”solr.TextFieldpositionIncrementGap=”100″>
       <analyzer type=”index”>
         <tokenizer class=”solr.WhitespaceTokenizerFactory“/>
修改为:
     <fieldType name=”text” class=”solr.TextField”>
       <analyzer type=”index” class=”org.apache.lucene.analysis.cjk.CJKAnalyzer”>
         <tokenizer class=”org.apache.lucene.analysis.cjk.CJKTokenizer“/>
找到如下两行:
       <analyzer type=”query”>
         <tokenizer class=”solr.WhitespaceTokenizerFactory“/>
修改为:
       <analyzer type=”query” class=”org.apache.lucene.analysis.cjk.CJKAnalyzer”>
         <tokenizer class=”org.apache.lucene.analysis.cjk.CJKTokenizer“/>
修改完毕,重新运行 Apache Solr 就可以对中文进行检索了,原先已经导入的文档需要重新导入。
记住原先的配置中有个 positionIncrementGap=”100″ 一定要删除了,否则会有异常。

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

This site uses Akismet to reduce spam. Learn how your comment data is processed.