Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solr中如何配置添加自定义词典呢? #2

Open
vaxilicaihouxian opened this issue Apr 22, 2016 · 11 comments
Open

solr中如何配置添加自定义词典呢? #2

vaxilicaihouxian opened this issue Apr 22, 2016 · 11 comments
Labels

Comments

@vaxilicaihouxian
Copy link

vaxilicaihouxian commented Apr 22, 2016

请给个配置示例好么?
这是我的schema.xml配置:

 <fieldType name="text_cn" class="solr.TextField">
            <analyzer type="index"  enableIndexMode="true" enableCustomDictionary="true">
                    <tokenizer class="com.hankcs.lucene.HanLPTokenizerFactory" enableCustomDictionary="true" customDictionaryPath="/home/macc/solr/dic/phone.txt"/>
        </analyzer>
        <analyzer type="query">
                <tokenizer class="com.hankcs.lucene.HanLPTokenizerFactory" enableIndexMode="false"/>
        </analyzer>
   </fieldType>
@hankcs
Copy link
Owner

hankcs commented Apr 22, 2016

<fieldType name="text_cn" class="solr.TextField">
    <analyzer type="index">
        <tokenizer class="com.hankcs.lucene.HanLPTokenizerFactory" enableIndexMode="true" customDictionaryPath="/home/macc/solr/dic/phone.txt"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="com.hankcs.lucene.HanLPTokenizerFactory" enableIndexMode="false"/>
    </analyzer>
</fieldType>

@hankcs
Copy link
Owner

hankcs commented Apr 22, 2016

启动后生成/home/macc/solr/dic/phone.txt.bin说明生效,下次修改词典必须先清除这个缓存

@vaxilicaihouxian
Copy link
Author

好的,我已经成功添加了自定义字典,但是有两个疑惑:
1.我清除*.bin缓存文件后,修改字典内容,然后访问solr node 并且reload了solr node core也没有再次生成缓存文件,即字典修改的内容并没有即时生效(修改前我已经清除了缓存文件),好像必须重启solr node。
2.自定义的词典中我加入了比如 "A5+ nz 1"这样的一条数据,测试这个filed建立索引的时候有如下字符串"黑米HMI A5+ MT6577双版本",索引结果与A5+相关的是:A 5 + 。三个字符分开了,并没有按我的字典内容进行分词,但是如果把A5+与MT6577中间的空格去除,就可以得到正确的A5+这个分词结果。请问我改如何修改自定义词典,或者有如何使用自定义词典的相关文档吗?

谢谢!!

@hankcs
Copy link
Owner

hankcs commented Apr 25, 2016

  1. 对,的确需要重新启动JVM。如果想更优雅地管理词典,需要自己编写额外的维护逻辑:HanLP对于用户自定义词典的官方推荐方法是怎样的? HanLP#182
  2. HanLP有自己的词典格式,其中空格是作为分隔符用的,请参考:https://github.com/hankcs/HanLP/wiki/FAQ#%E4%B8%BA%E4%BB%80%E4%B9%88%E8%87%AA%E5%AE%9A%E4%B9%89%E8%AF%8D%E5%85%B8%E5%8A%A0%E8%BD%BD%E5%A4%B1%E8%B4%A5 如果词语有空格,要么通过CustomDictionary.add添加,要么修改加载代码中的分隔符。未来版本将允许用户自定义分隔符。

@vaxilicaihouxian
Copy link
Author

您好,
还是我上面提到的问题 我想问一下这个分词器可否先按照whitespace分词 然后对每个部分的内容再进行hanlp的分词处理呢? 因为+这种符号的词性和空格的词性是一样的 我测试的结果是+后面有空格的话会把+和空格分词到一起,而这不是一个可以接受的结果。

hankcs added a commit to hankcs/HanLP that referenced this issue Apr 28, 2016
@hankcs
Copy link
Owner

hankcs commented Apr 28, 2016

感谢建议,已经做了改进。请重新打包或等候发布新版本。

dianhu pushed a commit to dianhu/HanLP that referenced this issue Jun 3, 2016
@hankcs
Copy link
Owner

hankcs commented Sep 1, 2018

@pengttyy
Copy link

@hankcs 有没有自定义词典的模板,不知道具体格式是怎样的

@hankcs
Copy link
Owner

hankcs commented Feb 28, 2020

@hankcs 有没有自定义词典的模板,不知道具体格式是怎样的

https://github.com/hankcs/HanLP/tree/1.x#8-%E7%94%A8%E6%88%B7%E8%87%AA%E5%AE%9A%E4%B9%89%E8%AF%8D%E5%85%B8

@duringall
Copy link

请给个配置示例好么?
这是我的schema.xml配置:

 <fieldType name="text_cn" class="solr.TextField">
            <analyzer type="index"  enableIndexMode="true" enableCustomDictionary="true">
                    <tokenizer class="com.hankcs.lucene.HanLPTokenizerFactory" enableCustomDictionary="true" customDictionaryPath="/home/macc/solr/dic/phone.txt"/>
        </analyzer>
        <analyzer type="query">
                <tokenizer class="com.hankcs.lucene.HanLPTokenizerFactory" enableIndexMode="false"/>
        </analyzer>
   </fieldType>
<fieldType name="text_cn" class="solr.TextField">
    <analyzer type="index">
        <tokenizer class="com.hankcs.lucene.HanLPTokenizerFactory" enableIndexMode="true" customDictionaryPath="/home/macc/solr/dic/phone.txt"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="com.hankcs.lucene.HanLPTokenizerFactory" enableIndexMode="false"/>
    </analyzer>
</fieldType>

hankcs老师您好,配置中的相对路径是根据什么,我在加载自定义词典时总是报找不到文件的错误,但是绝对路径可以读取

@hankcs
Copy link
Owner

hankcs commented Sep 22, 2020

相对路径视你的启动脚本而定,当前路径可用pwd命令获取。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants