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目录下 然后修 ...
随机推荐
- 智能社区--HI3516C可视门禁研发出来咯
铝壳.非常大气的外壳. 200W像素,HI3516C,携带server.创新的产品.欢迎交流:QQ237753582 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5u ...
- POJ 3342 Party at Hali-Bula (树形dp 树的最大独立集 判多解 好题)
Party at Hali-Bula Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5660 Accepted: 202 ...
- easyui中点击datagrid的分页刷新按钮,数据无法更新到最新状态
原因分析:点击刷新按钮是对当前页数据进行reload,因此所传的请求参数皆为上一次加载当前页的参数即datagrid的load方法中的参数,主要是因为请求的最终时间无法更新到最新状态 解决方案:对点击 ...
- C# PDF Page操作——设置页面切换按钮 C# 添加、读取Word脚注尾注 C#为什么不能像C/C++一样的支持函数只读传参 web 给大家分享一个好玩的东西,也许你那块就用的到
C# PDF Page操作——设置页面切换按钮 概述 在以下示例中,将介绍在PDF文档页面设置页面切换按钮的方法.示例中将页面切换按钮的添加分为了两种情况,一种是设置按钮跳转到首页.下页.上页或者 ...
- Cocos2D实现上下滚动式状态窗体
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 假设认为写的不好请多提意见,假设认为不错请多多支持点赞.谢谢! hopy ;) 有时候要显示的内容太多,我们无法在iOS设备的小屏幕上显示出来 ...
- simple-framework(MaliSDK框架分析)
simple-framework(Mali SDK框架分析) 1.全部的定义及实现放在同一个命名空间中.文件包括#include一般在命名空间的外面. 总的命名空间为namespace MaliSDK ...
- 【WinHec启发录】透过Windows 10技术布局,谈微软王者归来
每一个时代都有王者,王者的成功,往往是由于恰逢其时地公布了一个成功的产品(具有里程碑意义,划时代的产品).Windows 95的成功标示着微软是PC时代的王者:WinXP的成功标示着微软是互联网时代的 ...
- UVA1523-Helicopter(暴力+全排列)
题目链接 题意:有八个乘客坐在直升机上,求重心M最小值. 思路:依据题目所给的公式,我们能够知道要使得M最小.也就是要使得Mv和Mh的和最小,我们能够使用全排列,分别将每一个值放在各个位子上,然后更新 ...
- ubuntu下的root的创建进入与退出
创建: 在终端中输入:sudo passwd rootEnter new UNIX password: (在这输入你的密码)Retype new UNIX password: (确定你输入的密码)pa ...
- [Pa2013]Iloczyn
https://www.zybuluo.com/ysner/note/1300802 题面 给定正整数\(n\)和\(k\),问能否将\(n\)分解为\(k\)个不同正整数的乘积. \(n\leq10 ...