Home > Database > Mysql Tutorial > body text

solr4.4.0 集成 carrot2 支持中文和添加自己的中文分词器的方法

WBOY
Release: 2016-06-07 15:37:33
Original
2089 people have browsed it

默认 carrot2中是支持中文的,但是需要一个参数进行指定 carrot.lang= CHINESE_SIMPLIFIED carrot2支持的语言可以参考http://doc.carrot2.org/#div.attribute.lingo.MultilingualClustering.defaultLanguage 但是默认, carrot2使用的分词类是org.apache.luc

默认 carrot2中是支持中文的,但是需要一个参数进行指定

          carrot.lang=CHINESE_SIMPLIFIED 

carrot2支持的语言可以参考http://doc.carrot2.org/#div.attribute.lingo.MultilingualClustering.defaultLanguage


但是默认,carrot2使用的分词类是 org.apache.lucene.analysis.cn.smart.SentenceTokenizer,这是看 carrot源代码找到的源码如下(在org.apache.solr.handler.clustering.carrot2.LuceneCarrot2TokenizerFactory类中)

      private ChineseTokenizer() throws Exception {
        this.tempCharSequence = new MutableCharArray(new char[0]);


        // As Smart Chinese is not available during compile time,
        // we need to resort to reflection.
        final Class> tokenizerClass = ReflectionUtils.classForName(
            "org.apache.lucene.analysis.cn.smart.SentenceTokenizer", false);
        this.sentenceTokenizer = (Tokenizer) tokenizerClass.getConstructor(
            Reader.class).newInstance((Reader) null);
        this.tokenFilterClass = ReflectionUtils.classForName(
            "org.apache.lucene.analysis.cn.smart.WordTokenFilter", false);
      }

如果,没有这个类,carrot2默认就会使用一个 ExtendedWhitespaceTokenizer 使用空格进行切词,所以如果要使用carrot2自己的中文切词,需要加入  lucene-analyzers-smartcn-4.4.0.jar


当然也可以使用自己的分词包,比如IK等等,把上述源码替换成相应的类即可。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template