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

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

WBOY
WBOYOriginal
2016-06-07 15:37:332042Durchsuche

默认 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等等,把上述源码替换成相应的类即可。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn