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

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. 使用requireJS的shim參数,完毕jquery插件的载入

    没有requireJS框架之前,假设我们想使用jquery框架,会在HTML页面中通过<script>标签载入.这个时候jquery框架生成全局变量$和jQuery等全局变量.假设项目中引 ...

  2. redux 调试工具

    首先安装谷歌插件: redux-devtools 然后项目中安装插件:redux-devtools-extension 最后在创建 store 的时候进行配置: import { composeWit ...

  3. MySQLi 和 PDO 连接 MySQL

    PHP 连接 MySQL PHP 5 及以上版本建议使用以下方式连接 MySQL : MySQLi extension ("i" 意为 improved) PDO (PHP Dat ...

  4. Python爬虫开发【第1篇】【Json与JsonPath】

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,它使得人们很容易的进行阅读和编写.同时也方便了机器进行解析和生成.适用于进行数据交互的场景,比如网站前台与 ...

  5. 多台Mac电脑使用同一个apple开发者账号测试

    因为公司有苹果一体机,家里有macbook和黑苹果台式机,多台电脑用同一个开发者账号,每次真机调试时都是选择直接reset,回到另外一台电脑,又要重新设置,太麻烦了.直到最近才设置三台电脑都可以,分享 ...

  6. Cocos2dx如何引用第三方SO文件(Android NDK)

    做项目的过程中发现,引用第三方的库lib3rdsdk.so,当直接把lib3rdsdk.so放进armeabi文件夹里,会被删除掉.查网上资料都说的不全,经过实验,最简单的方法就是在jni下的andr ...

  7. bzoj 1924 所驼门王的宝藏

    题目大意: 有一个r*c的矩阵,上面有n个点有宝藏 每个有宝藏的点上都有传送门 传送门有三种:第一种可以传到该行任意一个有宝藏的点,第二种可以传到该列任意一个有宝藏的点,第三种可以传到周围的八连块上有 ...

  8. shell判断文件,目录是否存在或者具有权限 (转载)

    转自:http://cqfish.blog.51cto.com/622299/187188 文章来源:http://hi.baidu.com/haigang/blog/item/e5f582262d6 ...

  9. PCB Genesis加邮票孔(弧与弧)实现算法

    一.Genesis加邮票孔(弧与弧)实现算法 1.鼠标点击位置P点(可以确认搜索区域位置,确认点击位置周边元素分区,此所讲算法未应用到P点坐标) 2.求出:P1C与P2C (线与弧最近点距离的2个点) ...

  10. 0623-TP框架整理一(下载、入口文件、路由、创建控制器、调用模板、系统常量、命名空间)

    一.下载解压后用ThinkPHP(核心)文件 核心文件夹(ThinkPHP)不要改,是作用于全局的,有需要可以改应用目录(Application) 二.创建入口文件: 运行后出现欢迎界面,在说明系统自 ...