内容简介:直接使用 solr create -c coreName 创建core,会在server文件夹下的solr文件夹下得到新创建的core配置新建的core中,的conf文件夹下的solrconfig.xml文件,在新建的core中,的conf文件夹啊下,在solrconfig.xml文件后面加入
直接使用 solr create -c coreName 创建core,会在server文件夹下的solr文件夹下得到新创建的core
配置新建的core中,的conf文件夹下的solrconfig.xml文件,在新建的core中,的conf文件夹啊下,在solrconfig.xml文件后面加入
<!--引入DataImportHandler类的jar-->
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-.*\.jar" />
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">db-data-config.xml</str>
</lst>
</requestHandler>
这里的配置表示mycore的数据导入使用solr的DataImportHandler,而这个handler所在的jar位于E:solr-7.4.0solr-7.4.0dist目录里面,解压的时候就有,通过配置lib节点来进行引入。
配置managed-schema文件,与前面的solrconfig.xml文件在同一个目录下
<!--分词器-->
<fieldType name="content_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>
<!--添加对应于数据库字段的field-->
<!--配置从数据库导入到sorl中的数据的字段内容,所以每次要从数据库导入什么就需要配置什么-->
<!--name:指定域的名称,indexed:是否索引,type:指定域的类型,stored:是否存储,required:是否必须-->
<field name="product_name" type="string" indexed="true" stored="true"/>
<field name="product_price" type="string" indexed="true" stored="true"/>
<field name="product_description" type="content_ik" indexed="true" stored="true" multiValued="false" />
<field name="product_picture" type="string" indexed="true" stored="true"/>
<field name="product_catalog_name" type="content_ik" indexed="true" stored="true" multiValued="false" />
<!--设置部分字段搜索,当搜索条件为product_keywords时,会搜索以下所有字段匹配数据,-->
<!--multiValued:是否多值,比如商品信息中,一个商品有多张图片,一个Field想存储多个值的话,必须将multiValued设置为true-->
<field name="product_keywords" type="content_ik" indexed="true" stored="true" multiValued="true" />
<copyField source="product_name" dest="product_keywords" />
<copyField source="product_description" dest="product_keywords" />
<copyField source="product_price" dest="product_keywords"/>
<copyField source="product_catalog_name" dest="product_keywords"/>
需要注意的是,在设置了stored="ture",的时候,会将数据保存到solr中,所以,即使设置indexed="false",不建立索引,在搜索的时候,也能搜索到。
配置db-data-config.xml,这个是关联数据库的,可以将数据库中的数据,保存到solr中,要加 mysql 的jar包
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/solr?useSSL=false" user="root" password="123456"/>
<document>
<entity name="product" query="SELECT * FROM product">
<field column="pid" name="id" />
<field column="name" name="product_name" />
<field column="catalog_name" name="product_catalog_name" />
<field column="price" name="product_price" />
<field column="description" name="product_description" />
<field column="picture" name="product_picture" />
</entity>
</document>
</dataConfig>
三个文件的位置:
最后测试下,
导入数据库中的数据
搜索
可以成功得到数据库的数据,以及搜索到数据
在配置core中的文件的时候,一开始,我是直接复制的solr{home}exampleexample-DIHsolrdb下的文件
然后进行的配置。其他一切都正常,但是在搜索单个字符的时候,会搜索不到
具体不知道是什么原因
因为是新人,刚开始接触solr,所以还有非常多不懂的,基本上都是根据网上的资料来完成的,如果有问题麻烦各位大大帮忙指出来,感谢感谢
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Black Box Society
Frank Pasquale / Harvard University Press / 2015-1-5 / USD 35.00
Every day, corporations are connecting the dots about our personal behavior—silently scrutinizing clues left behind by our work habits and Internet use. The data compiled and portraits created are inc......一起来看看 《The Black Box Society》 这本书的介绍吧!