solr+jieba结巴分词

为什么选择结巴分词

  • 分词效率高
  • 词料库构建时使用的是jieba (python)

结巴分词Java版本

  • 下载
git clone https://github.com/huaban/jieba-analysis
  • 编译
cd jieba-analysis
mvn install
  • 注意
如果mvn版本较高,需要修改pom.xml文件,在plugins前面增加 

solr tokenizer版本

  • https://github.com/sing1ee/analyzer-solr (solr 5)
  • https://github.com/sing1ee/jieba-solr.git (solr 4)

支持solr 6或7或更高

如果你的solr像我一样,版本比较新,需要对代码稍做修改,但改动其实不大。(根据给编译时报的错误做修改即可)

build.gradle的diff

diff --git a/build.gradle b/build.gradle
index 2a87525..06c5cc3 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,4 +1,4 @@
-group = 'analyzer.solr5'
+group = 'analyzer.solr7'
version = '1.0'
apply plugin: 'java'
apply plugin: "eclipse"
@@ -14,15 +14,14 @@ repositories {
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'

- compile("org.apache.lucene:lucene-core:5.0.0")
- compile("org.apache.lucene:lucene-queryparser:5.0.0")
- compile("org.apache.lucene:lucene-analyzers-common:5.0.0")
- compile('com.huaban:jieba-analysis:1.0.0')
-// compile("org.fnlp:fnlp-core:2.0-SNAPSHOT")
+ compile("org.apache.lucene:lucene-core:7.1.0")
+ compile("org.apache.lucene:lucene-queryparser:7.1.0")
+ compile("org.apache.lucene:lucene-analyzers-common:7.1.0")
+ compile files('libs/jieba-analysis-1.0.3.jar')
compile("edu.stanford.nlp:stanford-corenlp:3.5.1")
}

task "create-dirs" << {
sourceSets*.java.srcDirs*.each { it.mkdirs() }
sourceSets*.resources.srcDirs*.each { it.mkdirs() }
-}
\ No newline at end of file
+}

编译

./gladlew build

集成到solr

拷贝jar包到solr的目录下:server/solr-webapp/webapp/WEB-INF/lib

schema修改

    <fieldType name="text_jieba" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="analyzer.solr7.jieba.JiebaTokenizerFactory"  segMode="SEARCH"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_ch.txt" />
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.SnowballPorterFilterFactory" language="English"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="analyzer.solr7.jieba.JiebaTokenizerFactory"  segMode="SEARCH"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_ch.txt" />
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.SnowballPorterFilterFactory" language="English"/>
      </analyzer>
    </fieldType>

转载于:https://www.cnblogs.com/lotushy/p/8404603.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值