solr数据导入和添加中文分词器

首先修改solrConfig.xml文件

备份_default文件夹

修改solrconfig.xml

加入如下内容

 

官方示例:
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
  <lst name="defaults">
    <str name="config">/path/to/my/DIHconfigfile.xml</str>
  </lst>
</requestHandler>

 

效果:

 

在conf目录建立一个db-data-config.xml文件

 

复制代码

<dataConfig>
    <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/demo" user="root" password="123" />
    <document>
        <entity name="bless" query="select * from bless"
                deltaQuery="select bless_id from bless where bless_time > '${dataimporter.last_index_time}'">
            <field column="BLESS_ID" name="blessId" />
            <field column="BLESS_CONTENT" name="blessContent" />
            <field column="BLESS_TIME" name="blessTime" />
        </entity>
    </document>
</dataConfig>

复制代码

 

 

 我的数据库

 

 

复制jar

找到这个:

连同mysql驱动包一起复制到

 

找到自带的中文分词器

复制到webapp的lib目录

 

 修改managed-shchema

在最后加入如下中文配置

复制代码

    <!-- ChineseAnalyzer -->
    <fieldType name="solr_cnAnalyzer" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/>
      </analyzer>
    </fieldType>

复制代码

 

 

下面以cloud模式启动

 整个过程只需要输入 索引集合 的名称,其他都是一路回车。

复制代码

D:\>cd solr-7.1.0

D:\solr-7.1.0>bin\solr start -e cloud

Welcome to the SolrCloud example!

This interactive session will help you launch a SolrCloud cluster on your local
workstation.
To begin, how many Solr nodes would you like to run in your local cluster? (spec
ify 1-4 nodes) [2]:
【回车】
Ok, let's start up 2 Solr nodes for your example SolrCloud cluster.
Please enter the port for node1 [8983]:
【回车】
Please enter the port for node2 [7574]:
【回车】
Solr home directory D:\solr-7.1.0\example\cloud\node1\solr already exists.
D:\solr-7.1.0\example\cloud\node2 already exists.

Starting up Solr on port 8983 using command:
"D:\solr-7.1.0\bin\solr.cmd" start -cloud -p 8983 -s "D:\solr-7.1.0\example\clou
d\node1\solr"

Waiting up to 30 to see Solr running on port 8983

Starting up Solr on port 7574 using command:
"D:\solr-7.1.0\bin\solr.cmd" start -cloud -p 7574 -s "D:\solr-7.1.0\example\clou
d\node2\solr" -z localhost:9983

Started Solr server on port 8983. Happy searching!
Waiting up to 30 to see Solr running on port 7574
INFO  - 2017-11-04 12:35:02.823; org.apache.solr.client.solrj.impl.ZkClientClust
erStateProvider; Cluster at localhost:9983 ready

Now let's create a new collection for indexing documents in your 2-node cluster.

Please provide a name for your new collection: [gettingstarted]
Started Solr server on port 7574. Happy searching!
bless【输入名称并回车】
How many shards would you like to split bless into? [2]
【回车】
How many replicas per shard would you like to create? [2]
【回车】
Please choose a configuration for the bless collection, available options are:
_default or sample_techproducts_configs [_default]
【回车】
Created collection 'bless' with 2 shard(s), 2 replica(s) with config-set 'bless'


Enabling auto soft-commits with maxTime 3 secs using the Config API

POSTing request to Config API: http://localhost:8983/solr/bless/config
{"set-property":{"updateHandler.autoSoftCommit.maxTime":"3000"}}
Successfully set-property updateHandler.autoSoftCommit.maxTime to 3000


SolrCloud example running, please visit: http://localhost:8983/solr


D:\solr-7.1.0>

复制代码

 

 下面访问

选择bless

然后选择Schema,来配置字段【注意:这里的名字要与数据库中的字段名一模一样!!!】

bless_id

bless_content

 

bless_time

 

 

点击DataImport

要注意勾选Auto-Refresh Status

 

现在点击Query。可以看到,数据库中的数据都导入了。

 

下面看一下中文分词

看起来还不错。查询试试看。

发现0条数据,至少也得有一条啊!然而如果我指定默认搜索字段。会发现出来了。

 试试搜索【心】

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Solr基于Lucene的全文搜索服务。同时对其进行了扩展,提供了比Lucene更为丰富的查询语言,同时实现了可配置、可扩展并对查询性能进行了优化,并且提供了一个完善的功能管理界面,是一款非常优秀的全文搜索引擎 课程特点毕业后接触的第一个中间件就是Solr,在工作中用处广泛,为了便于大家快速掌握该技能,开始录制相关课程,该专栏特点如下:1.采用Solr最新版本视频录制,全网最新课程(Solr8.1于2019年5月16日发布)2.技能点全网最全,会结合工作经验,项目中用到的技能点都会有所涉及,更新章节比较全面3.适用范围广,从零基础到高级架构以及分布式集群都涵盖,适用初级、高级、项目实战等多个层次开发者4.多种维度辅助学习,采用独立solr粉丝群辅助教学,学员问题会及时得到解决,程序员突破圈 打卡制度,督促学员学习关注后再购买、 关注后再购买、 关注后再购买课程能得到什么1.快速学习到最新版本的全文检索技术,从视频、文章、圈子、粉丝交流等快速促进学习2.通过该技术,获得面试进阶指导3.结交人脉(庞大的粉丝群)..End初期学员100人,价格不会太高,也是为了帮助更多的开发者但是个人精力有限,所以限制条件如下1.求知欲强,有想向技术更深一层了解的2.乐于交流,喜欢探讨技术者3.学习惰性者慎入,购买后会督促大家学习,购买不是目的,学习到该技能才是该专栏的主要目的正式进入学习状态了吗,专栏群见。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值