PS:淘淘商城笔记
1、在solr中默认是中文分析器,需要手工配置。配置一个FieldType,在FieldType中指定中文分析器。
2、Solr中的字段必须是先定义后使用。
中文分析器的配置
第一步:使用IK-Analyzer。把分析器的文件夹上传到服务器。
第二步:需要把分析器的jar包添加到solr工程中。
[root@bogon IK Analyzer 2012FF_hf1]# cp IKAnalyzer2012FF_u1.jar /usr/local/solr/tomcat/webapps/solr/WEB-INF/lib/
[root@bogon IK Analyzer 2012FF_hf1]#
第三步:需要把IKAnalyzer需要的扩展词典及停用词词典、配置文件复制到solr工程的classpath。
/usr/local/solr/tomcat/webapps/solr/WEB-INF/classes
[root@bogon IK Analyzer 2012FF_hf1]# cp IKAnalyzer.cfg.xml ext_stopword.dic mydict.dic /usr/local/solr/tomcat/webapps/solr/WEB-INF/classes
[root@bogon IK Analyzer 2012FF_hf1]#
注意:扩展词典及停用词词典的字符集必须是utf-8。不能使用windows记事本编辑。
第四步:配置fieldType。需要在solrhome/collection1/conf/schema.xml中配置。
技巧:使用vi、vim跳转到文档开头gg。跳转到文档末尾:G
<fieldType name="text_ik" class="solr.TextField">
<analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>
</fieldType>
业务字段配置
业务字段判断标准:
1、在搜索时是否需要在此字段上进行搜索。例如:商品名称、商品的卖点、商品的描述
2、后续的业务是否需要用到此字段。例如:商品id。
需要用到的字段:
1、商品id
2、商品title
3、卖点
4、价格
5、商品图片
6、商品分类名称
7、商品描述
Solr中的业务字段:
1、id——》商品id
其他的对应字段创建solr的字段。
<field name="item_title" type="text_ik" indexed="true" stored="true"/>
<field name="item_sell_point" type="text_ik" indexed="true" stored="true"/>
<field name="item_price" type="long" indexed="true" stored="true"/>
<field name="item_image" type="string" indexed="false" stored="true" />
<field name="item_category_name" type="string" indexed="true" stored="true" />
<field name="item_desc" type="text_ik" indexed="true" stored="false" />
<field name="item_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/>
<copyField source="item_title" dest="item_keywords"/>
<copyField source="item_sell_point" dest="item_keywords"/>
<copyField source="item_category_name" dest="item_keywords"/>
<copyField source="item_desc" dest="item_keywords"/>
重新启动tomcat