zoukankan      html  css  js  c++  java
  • solr添加IK分词和自己定义词库

     下载IK分词IK Analyzer 2012FF_hf1.zip

    下载地址:http://yunpan.cn/cdvATy8899Lrw (提取码:c10d)

    1、将IKAnalyzer2012FF_u1.jar包上传到服务器,复制到solr-4.10.4/example/solr-webapp/webapp/WEB-INF/lib目录下

    2、solr-4.10.4/example/solr-webapp/webapp/WEB-INF目录下创建目录classes,然后把IKAnalyzer.cfg.xmlstopword.dic拷贝到新创建的classes目录下即可

    3:修改solr core的schema文件,默认是solr-4.10.4/example/solr/collection1/conf/schema.xml,添加如下配置

         <fieldType name="text_ik" class="solr.TextField">

            <!--索引时候的分词器-->
    <analyzer type="index" isMaxWordLength="false" class="org.wltea.analyzer.lucene.IKAnalyzer"/>
    <!--查询时候的分词器-->
    <analyzer type="query" isMaxWordLength="true" class="org.wltea.analyzer.lucene.IKAnalyzer"/>
    </fieldType>

    4、启动solr集群

    自定义词库

    到sougou 下载对应的词库:http://pinyin.sogou.com/dict/

    由于sougou 下载后的文件是scel 格式不能直接用,需要用工具转化下格式,推荐使用深蓝工具,下载地址

    http://yunpan.cn/cmuyuQhCasFMR (提取码:6432)

    然后将文件格式转化为dic结尾的。词库的文件格式必需是:无BOM的UTF-8格式,分词库可以为多个,以分号隔开即可。

    将下载的词库复制到/home/hadoop/cloudsolr/solr-4.10.4/example/solr-webapp/webapp/WEB-INF/classes目录下

    修改配置文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
    <properties>
            <comment>IK Analyzer 扩展配置</comment>
            <!--用户可以在这里配置自己的扩展字典 
            <entry key="ext_dict">ext.dic;</entry> 
            -->
            <entry jey = "mingxing">mingxing.scel</entry>
            <!--用户可以在这里配置自己的扩展停止词字典-->
            <entry key="ext_stopwords">stopword.dic;</entry>
    
    </properties>


    重启solr集群

    测试结果:

     这样分词有一个问题:分词方式是按照maxword 的方式

    集群启动的时候主节点不会报错。从节点会报错

    配置文件信息如下:

    IK的lib文件已经上传

    改配置的都配置了,启动还是报错:

    {msg=SolrCore 'collection1' is not available due to init failure: Could not load conf for core collection1: Plugin init failure for [schema.xml] fieldType "text_ik": Cannot load analyzer: org.wltea.analyzer.lucene.IKAnalyzer. Schema file is /configs/myconf/schema.xml,trace=org.apache.solr.common.SolrException: SolrCore 'collection1' is not available due to init failure: Could not load conf for core collection1: Plugin init failure for [schema.xml] fieldType "text_ik": Cannot load analyzer: org.wltea.analyzer.lucene.IKAnalyzer. Schema file is /configs/myconf/schema.xml
    	at org.apache.solr.core.CoreContainer.getCore(CoreContainer.java:745)
    	at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:347)
    

     问题原因:

    配置了IK分词后,没有同步到zk,删掉zkdata 里面的数据重新启动zk即可

  • 相关阅读:
    beta分布
    python中os.walk浏览目录和文件
    (zz)Linux下Gcc生成和使用静态库和动态库详解
    GNU scientific library
    python 字典有序无序及查找效率,hash表
    Python代码分析工具之dis模块
    python里的坑。http://www.pythoner.com/356.html
    python实现单向链表
    Python 执行字符串表达式函数(eval exec execfile)
    版本管理神器git上手
  • 原文地址:https://www.cnblogs.com/zhanggl/p/4727432.html
Copyright © 2011-2022 走看看