目录java
添加一个文档数据库
查询添加的文档tomcat
以上详细介绍了query里面的参数详解。性能
当不输入任何条件时,进行查询,看看返回结果。spa
返回了刚才添加进去的文档。3d
添加文档时,咱们添加了id,title,content 分词,那么若是咱们想本身定义,该如何?code
{"id":"change.me","aaaaaa":"change.me"}
结果返回错误:xml
Status: error Error: Bad Request Error: { "responseHeader": { "status": 400, "QTime": 1 }, "error": { "msg": "ERROR: [doc=change.me] unknown field 'aaaaaa'", "code": 400 } }
不能发现 aaaaaa 这个filed!!blog
1.Schema.xml索引
schema.xml位于solr/conf/目录下,相似于数据表配置文件,定义了加入索引的数据的数据类型,主要包括type、fields和其余的一些缺省设置。
Field:域的定义
dynamicField:动态域
存储的都是一些solr内置的字段。
能够本身定义一些字段和类型
solr/collection1/conf
找到Schema.xml文件,进行添加
<!-- Anny 配置字段--> <field name="title_ik" type="text_ik" indexed="true" stored="true"/> <field name="content_ik" type="text_ik" indexed="true" stored="true" multiValued="true"/> <!-- IKAnalyzer- 配置类型-> 采用中文分词器 <fieldType name="text_ik" class="solr.TextField"> <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/> </fieldType> <!--IKAnalyzer Field-->
配置步骤:
jar包下载地址:http://pan.baidu.com/s/1skphG9v
IKAnalyzer.cfg.xml配置文件
<?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 key="ext_stopwords">stopword.dic;</entry> </properties>
ext.dic配置文件
惠民
中商惠民www
baby
屌丝男士
野菊花
向日葵
菊花
葵花
注:若是文档第一行的词,没有进行分词处理,那么就验证了第一行不进行分词。能够空一行!
配置完毕后,进行重启tomcat便可访问。
将数据库的字段建立类型和域
<!--product--> <field name="product_name" type="text_ik" indexed="true" stored="true"/> <field name="product_price" type="float" indexed="true" stored="true"/> <field name="product_description" type="text_ik" indexed="true" stored="false" /> <field name="product_picture" type="string" indexed="false" stored="true" /> <field name="product_catalog_name" type="string" indexed="true" stored="true" /> <field name="product_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/> <copyField source="product_name" dest="product_keywords"/> <copyField source="product_description" dest="product_keywords"/>
copyField域
<copyField source="product_name" dest="product_keywords"/> 建立索引product_name,复制到product_keywords里面了。把多个域的关键词复制到同一个域,多个域时,能够放到一个域中。就不用定义那么多域了。搜索比较方便。