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 -->
---------------------
Solr搜索引擎 — 通过mysql配置数据源的更多相关文章
- Solr DIH以Mysql为数据源批量创建索引
演示使用solr管理后台,以mysql为数据源,批量建索引的方法 测试于:Solr 4.5.1, mmseg4j 1.9.1, Jdk 1.6.0_45, Tomcat 6.0.37 | CentOS ...
- spring mysql多数据源配置
spring mysql多数据源配置 @Configuration public class QuartzConfig { @Autowired private AutowireJobFactory ...
- MySQL ODBC驱动安装和配置数据源
一.MySQL的ODBC驱动下载及安装 步骤一:下载ODBC驱动安装包 1.下载地址: https://dev.mysql.com/downloads/connector/odbc/ 2.选择适合自己 ...
- solr 4.3.0 配置
scheme.xml <?xml version="1.0" encoding="UTF-8" ?> <schema name="t ...
- 使用solr批量导入mysql数据库,以及Unable to read: dataimport.properties等坑
折腾了一下午终于成功了!先放一张成功图: 成功把mysql的数据添加进去了,我这里是整合了tomcat9,整合步骤挺麻烦的,百度一大堆! 这里主要介绍批量导入数据,这里有些坑,所以记录一下: 步骤: ...
- JAVAEE——Solr:安装及配置、后台管理索引库、 使用SolrJ管理索引库、仿京东的电商搜索案例实现
1 学习回顾 1. Lucene 是Apache开源的全文检索的工具包 创建索引 查询索引 2. 遇到问题? 文件名 及文件内容 顺序扫描法 全文检索 3. 什么是全文检索? 这种先创建索引 再 ...
- Elasticsearch vs Solr 搜索引擎对比和选型
前言 全文搜索属于最常见的需求,开源的 Elasticsearch 是目前全文搜索引擎的首选. 基于Lucene它可以快速地储存.搜索和分析海量数据.维基百科.Stack Overflow.Githu ...
- macOS安装Solr并索引MySQL
安装 Java 语言的软件开发工具包 brew cask install java 或者在 Oracle官网 中选择 Mac 版本 jdk-8u111-macosx-x64.dmg 下载并安装. 安装 ...
- jboss配置数据源
配置的是mysql的数据源 找到jboss-.GA\docs\examples\jca\mysql-ds.xml 复制一份到jboss-.GA\server\default\deploy目录下 然后修 ...
随机推荐
- android:省市县三级联动(基于json和spring)
一.请看效果图": 二.程序的代码: 1.MainActivity.java package com.loveplusplus.loader.demo.ui; import org.json ...
- javascript闭包具体解释
今天我们从内存结构上来解说下 javascript中的闭包概念. 闭包:是指有权訪问另外一个函数作用域中的变量的函数. 创建闭包的常见方式就是在一个函数内部创建另外一个函数. 在javascript中 ...
- DSPC6748中某问题的解决方式
因为之前没有做过DSP相关的开发,属于菜鸟中的菜鸟.出现故障后.不知道从哪方面来解决这些小问题. 开发环境:CCS5.5.0 开发板:TI公司的TMS320C6748 问题: 控制台出现初始化结束后多 ...
- GraphDatabase_action
https://neo4j.com/docs/ #https://pypi.python.org/pypi/neo4j-driver/1.5.3from neo4j.v1 import GraphDa ...
- ubuntu安装virtualbox
1.下载 2.sudo dpkg -i virtualbox-5.2_5.2.10-122088_Ubuntu_xenial_amd64.deb $sudo dpkg -i virtualbox-5. ...
- USACO 刷题有感
最近每天都尽量保持着每天一道USACO的题目,呵呵,一开始都是满简单的,一看题目基本上思路就哗啦啦地出来了,只不过代码实现有点麻烦,花了一些时间去调试,总体感觉还不错,但是越往后做,应该就很难保持一天 ...
- Java 系统工具类 —— System、Scanner、Runtime
0. 静态成员变量 System.out:是 PrinterStream 型变量: public final class System { ... public final static InputS ...
- luogu 1726 上白泽惠音
题目大意: 给一个有向图 求一个最大的强连通分量,输出这个强连通分量里的所有元素 若两个联通分量内点数相同 则输出字典序小的那个 思路: 直接tarjan 对每个连通分量,求一下最小点,然后判断字典序 ...
- Python Matplotlib模块--pylab
#-*- coding: utf-8 -*- ''' subplot(m,n,p):其中,m表示是图排成m行,n表示图排成n列,也就是整个figure中有n个图是排成一行的,一共m行,如果m=2就是表 ...
- P4097 [HEOI2013]Segment
传送门 简单来说就是对于每条线段,先把它拆成\(O(logn)\)条,然后对于每一条再\(O(logn)\)判断在所有子区间的优劣程度 //minamoto #include<bits/stdc ...