1 cmd:某个网站做索引部署
(c) 2019 Microsoft Corporation。保留所有权利。
C:\Users\Administrator>d:
D:\>cd solr
D:\solr>cd solr*
D:\solr\solr-8.6.1>cd solr*
D:\solr\solr-8.6.1\solr-8.6.1>cd bin
D:\solr\solr-8.6.1\solr-8.6.1\bin>solr start
Waiting up to 30 to see Solr running on port 8983
Started Solr server on port 8983. Happy searching!
D:\solr\solr-8.6.1\solr-8.6.1\bin>solr create_collection -c mes
WARNING: Using _default configset with data driven schema functionality. NOT RECOMMENDED for production use.
To turn off: bin\solr config -c mes -p 8983 -action set-user-property -property update.autoCreateFields -value false
Created new core 'mes'
D:\solr\solr-8.6.1\solr-8.6.1\bin>
结果:打开http://localhost:8983/solr/#/,左侧core中出现mes
2 配置文件
(1)cmd索引部署成功后,solr文件夹下会生成相应的文件,其中conf中有配置文件
(2)打开managed-schema
- 中文分词(IK-Analyzer)设置
中文分词支持细粒度和智能分词两种切分模式,其中智能模式适合用于查询,细粒度模式用于建立索引(分得比较细致):
- 在managed-schema中添加分词器
<fieldType name="text_ik" class="solr.TextField">
<!--索引时候的分词器,智能模式为false-->
<analyzer type="index">
<tokenizer class="org.wltea.analyzer.util.IKTokenizerFactory" useSmart=“false"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<!--查询时候的分词器,智能模式为true-->
<analyzer type="query">
<tokenizer class="org.wltea.analyzer.util.IKTokenizerFactory" useSmart=“true"/>
</analyzer>
</fieldType>
- 在managed-schema中添加自定义字段,根据字段建立索引
<!--type为分词器的name,title与content为自定义的字段,用于索引-->
<field name="title" type="text_ik" indexed="true" stored="true" multiValued="true"/>
<field name="content" type="text_ik" indexed="true" stored="true" multiValued="true"/>
(3)打开solrconfig.xml,添加引用的jar包
<lib dir="${solr.install.dir:../..}/contrib/IKAnalyzer/lib" regex=".*\.jar" />
3 重启solr
solr restart -p 8983
4 测试
Analyzis页面的FieldType多出类型text_id,并且索引和查询的分词结果不同。