一,准备数据库
数据表结构

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 &lt;!-- 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. --&gt; &lt;!-- add property --&gt; <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">data-config.xml</str> </lst> </requestHandler> &lt;!-- 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 --&gt;(1周前#7楼)

5201314jie: > vim server/solr/new_core/conf/solrconfig.xml &lt;!-- 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. --&gt; &lt;!-- add property --&gt; <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">data-config.xml</str> </lst> </requestHandler> &lt;!-- 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 --&gt;
---------------------

Solr搜索引擎 — 通过mysql配置数据源的更多相关文章

  1. Solr DIH以Mysql为数据源批量创建索引

    演示使用solr管理后台,以mysql为数据源,批量建索引的方法 测试于:Solr 4.5.1, mmseg4j 1.9.1, Jdk 1.6.0_45, Tomcat 6.0.37 | CentOS ...

  2. spring mysql多数据源配置

    spring mysql多数据源配置 @Configuration public class QuartzConfig { @Autowired private AutowireJobFactory ...

  3. MySQL ODBC驱动安装和配置数据源

    一.MySQL的ODBC驱动下载及安装 步骤一:下载ODBC驱动安装包 1.下载地址: https://dev.mysql.com/downloads/connector/odbc/ 2.选择适合自己 ...

  4. solr 4.3.0 配置

    scheme.xml <?xml version="1.0" encoding="UTF-8" ?> <schema name="t ...

  5. 使用solr批量导入mysql数据库,以及Unable to read: dataimport.properties等坑

    折腾了一下午终于成功了!先放一张成功图: 成功把mysql的数据添加进去了,我这里是整合了tomcat9,整合步骤挺麻烦的,百度一大堆! 这里主要介绍批量导入数据,这里有些坑,所以记录一下: 步骤: ...

  6. JAVAEE——Solr:安装及配置、后台管理索引库、 使用SolrJ管理索引库、仿京东的电商搜索案例实现

    1 学习回顾 1. Lucene  是Apache开源的全文检索的工具包 创建索引 查询索引 2. 遇到问题? 文件名 及文件内容  顺序扫描法  全文检索 3. 什么是全文检索? 这种先创建索引 再 ...

  7. Elasticsearch vs Solr 搜索引擎对比和选型

    前言 全文搜索属于最常见的需求,开源的 Elasticsearch 是目前全文搜索引擎的首选. 基于Lucene它可以快速地储存.搜索和分析海量数据.维基百科.Stack Overflow.Githu ...

  8. macOS安装Solr并索引MySQL

    安装 Java 语言的软件开发工具包 brew cask install java 或者在 Oracle官网 中选择 Mac 版本 jdk-8u111-macosx-x64.dmg 下载并安装. 安装 ...

  9. jboss配置数据源

    配置的是mysql的数据源 找到jboss-.GA\docs\examples\jca\mysql-ds.xml 复制一份到jboss-.GA\server\default\deploy目录下 然后修 ...

随机推荐

  1. 【hdu3518】Boring counting

    题意:找出一个字符串中至少重复出现两次的字串的个数(重复出现时不能重叠). 后缀数组 枚举字串长度h,对于每一次的h,利用height数组,找出连续的height大于等于h的里面最左端和最右端得为之l ...

  2. YTU 2516: 剪刀石头布

    2516: 剪刀石头布 时间限制: 1 Sec  内存限制: 128 MB 提交: 193  解决: 123 题目描述 小慧小时候很喜欢和她的小伙伴们一起玩剪刀(Scissors).石头(Rock). ...

  3. c#调用oracle存储过程返回数据集

    c#调用oracle存储过程返回数据集 2008-12-20 10:59:57|  分类: net|字号 订阅   CREATE OR REPLACE PACKAGE pkg_tableTypeIS  ...

  4. poj 2762(tarjan缩点+判断是否是单链)

    Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19234 ...

  5. poj1286 Necklace of Beads—— Polya定理

    题目:http://poj.org/problem?id=1286 真·Polya定理模板题: 写完以后感觉理解更深刻了呢. 代码如下: #include<iostream> #inclu ...

  6. 如何在BCGControlBar工程的工具栏里面新增下拉列表控件

    通常情况下,工具栏里面都是一些按钮和图片,很少可以看到下拉列表控件,但是在某些应用场合,也需要用到下拉列表控件.今天在这里就简单讲解下如何在工具栏里添加下拉列表控件.   添加的过程也比较简单,在CM ...

  7. 【148】DevExpress相关控件使用

    ---------------------------------------------------------------------------------------------------- ...

  8. 【409】Linux 系统 Testrun

    文件名:Testrun #!/bin/sh PROG=./puzzle case $1 in 1) T=Tests/bad* ;; 2) T=Tests/sol* ;; 3) T=Tests/unso ...

  9. Linux系统下 为命令配置别名

    1.什么是别名 在管理和维护Linux系统的过程中,将会使用到大量命令,有一些很长的命令或用法经常被用到,重复而频繁的输入某个很长命令或用法是不可取的.这时可以使用 别名 功能将这个过程简单化. Li ...

  10. python自动化测试学习笔记-7面向对象编程,类,继承,实例变量,邮件

    面向对象编程(OOP)术语: class TestClass(object):   val1 = 100       def __init__(self):     self.val2 = 200   ...