Solr搜索引擎 — 通过mysql配置数据源
一,准备数据库
数据表结构
CREATE TABLE `app` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`app_name` varchar(255) NOT NULL DEFAULT '',
`score` decimal(10,5) NOT NULL DEFAULT '0.00000',
`downLoadNum` int(10) NOT NULL DEFAULT '0',
`top` int(10) NOT NULL DEFAULT '0',
`type` int(10) NOT NULL DEFAULT '1',
`update_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
1
2
3
4
5
6
7
8
9
10
生成一些测试数据
因为我们需要使用mysql作为数据源,我们需要增加对mysql使用的jar包
> cd server/solr-webapp/webapp/WEB-INF/lib/
> wget http://pic.w-blog.cn/mysql-connector-java.jar
1
2
二、增加solr-core
PS:这里基础solr命令启动的程序并未基于tomcat进行配置,后续cloud集群会使用tomcat进配置
尝试增加一个core会提示找不到配置,复制一份默认的配置文件
> cp -r server/solr/configsets/_default server/solr/new_core
1
在solrconfig.xml 下添加以下配置,添加位置大约在 680行,SearchHandler 配置上面:
> vim server/solr/new_core/conf/solrconfig.xml
<!-- Request Handlers
http://wiki.apache.org/solr/SolrRequestHandler
Incoming queries will be dispatched to a specific handler by name
based on the path specified in the request.
If a Request Handler is declared with startup="lazy", then it will
not be initialized until the first request that uses it.
-->
<!-- add property -->
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
<!-- SearchHandler
http://wiki.apache.org/solr/SearchHandler
For processing Search Queries, the primary Request Handler
provided with Solr is "SearchHandler" It delegates to a sequent
of SearchComponents (see below) and supports distributed
queries across multiple shards
-->
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
该文件的配置如下,连接的是mysql也支持其他的数据库
query:查询数据库表符合记录数据
deltaQuery:增量索引查询主键ID 注意这个只能返回ID字段
deltaImportQuery:增量索引查询导入的数据
> vim server/solr/new_core/conf/data-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<dataConfig>
<dataSource name="source"
type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/appstore"
user="root"
password="123456"
/>
<document>
<entity name="app"
pk="id"
dataSource="source"
query="select * from app"
deltaImportQuery="select * from app where id = '${dih.delta.id}'"
deltaQuery="select id from app where update_date > '${dataimporter.last_index_time}' and type = 1">
<field column="id" name="id"/>
<field column="update_date" name="update_date"/>
</entity>
</document>
</dataConfig>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
在这之后,需要配置managed-schema文件,与数据库进行映射,在117行附近,添加与数据库的映射,具体添加规则,不详细写了。
> vim server/solr/new_core/conf/managed-schema
<!-- add propertity -->
<field name="appName" type="string" indexed="true" stored="true" />
<field name="score" type="string" indexed="true" stored="true" />
<field name="downLoadNum" type="string" indexed="true" stored="true" />
<field name="top" type="string" indexed="true" stored="true" />
<field name="type" type="string" indexed="true" stored="true" />
<field name="update_date" type="string" indexed="true" stored="true" />
1
2
3
4
5
6
7
8
9
重启solr
> solr restart -force
1
再次增加core发现已经可以增加成功
初始化数据
初始化完成就可以进行查询了
如果修改了可以触发更新操作
当然也可以通过请求URL的方式进行数据更新,这里也方便索引的更新和程序相结合
http://172.16.3.148:8983/solr/new_core/dataimport?command=delta-import&clean=%20false&commit=true&wt=json&indent=true&verbose=false&optimize=false&debug=false
1
Solr搜索引擎 — 两种安装方式
阅读数 52
常常在业务开发中会遇到大列表的查询需求或者按照各项条件搜索内容,一般的做法往往都是数据库直接搞定,但是到了一定的程度只有这类需求会带来巨大的开销,一个表格中涉及到了5张表的数据,搜索要求从其中3张表的...
博文
来自: 喵了个咪的博客
csdnhsh: 有些复杂了吧(1周前#8楼)
5201314jie: > vim server/solr/new_core/conf/solrconfig.xml <!-- Request Handlers http://wiki.apache.org/solr/SolrRequestHandler Incoming queries will be dispatched to a specific handler by name based on the path specified in the request. If a Request Handler is declared with startup="lazy", then it will not be initialized until the first request that uses it. --> <!-- add property --> <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">data-config.xml</str> </lst> </requestHandler> <!-- SearchHandler http://wiki.apache.org/solr/SearchHandler For processing Search Queries, the primary Request Handler provided with Solr is "SearchHandler" It delegates to a sequent of SearchComponents (see below) and supports distributed queries across multiple shards -->(1周前#7楼)
5201314jie: > vim server/solr/new_core/conf/solrconfig.xml <!-- Request Handlers http://wiki.apache.org/solr/SolrRequestHandler Incoming queries will be dispatched to a specific handler by name based on the path specified in the request. If a Request Handler is declared with startup="lazy", then it will not be initialized until the first request that uses it. --> <!-- add property --> <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">data-config.xml</str> </lst> </requestHandler> <!-- SearchHandler http://wiki.apache.org/solr/SearchHandler For processing Search Queries, the primary Request Handler provided with Solr is "SearchHandler" It delegates to a sequent of SearchComponents (see below) and supports distributed queries across multiple shards -->
---------------------
相关文章
- mysql数据库的初始化及相关配置
- 【MySQL】慢查询的配置与使用
- 【数据库开发】在Windows上和Linux上配置MySQL的过程
- mysql-模拟全连接处理
- [sql]mysql参数(配置)手册
- 在CentOS中安装Mysql数据库
- 005.MySQL双主-Master01可用配置
- WampServer Mysql配置
- Python编程:records批量插入数据到mysql
- 【mysql】恢复备份
- [数据库/MySQL]数据库备份与升级:MySQL Percona(RPM) 5.7.24-27 升级到 5.7.31-34
- mysql 对应数据库服务器配置 所能承受的tps和qps
- Mysql性能优化、Mysql参数优化、Mysql配置优化
- MySQL的安装与配置
- windows下mysql免安装配置
- CentOS6.4下Mysql数据库的安装与配置,导入数据库,授权远程ip
- 怎样快速地迁移 MySQL 中的数据?
- mysql 导入数据到postgresql
- postgresql与lightdb中的null行为及oracle、mysql的兼容性
- Linux(Centos7)离线安装mysql
- springboot2 zipkin mysql
- mysql主从复制的配置总结
- Springboot 配置 application.yml 连接MySQL数据库
- mysql二进制包安装与配置实战记录
- PHP__MySQL数据库相关操作