2019独角兽企业重金招聘Python工程师标准>>>

上一节我们已经通过两种方式运行了solr,本节演示怎么配置solr的mysql数据源

附上:

喵了个咪的博客:http://w-blog.cn

Solr官网:http://lucene.apache.org/solr/

> PS:8.0.0版本已经发布,本文使用此时较为稳定的7.7.1版本

一,准备数据库

数据表结构

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;

生成一些测试数据

因为我们需要使用mysql作为数据源,我们需要增加对mysql使用的jar包

> cd server/solr-webapp/webapp/WEB-INF/lib/
> wget http://pic.w-blog.cn/mysql-connector-java.jar

二、增加solr-core

> PS:这里基础solr命令启动的程序并未基于tomcat进行配置,后续cloud集群会使用tomcat进配置

尝试增加一个core会提示找不到配置,复制一份默认的配置文件

> cp -r server/solr/configsets/_default server/solr/new_core

在solrconfig.xml 下添加以下配置,添加位置大约在 680行,SearchHandler 配置上面:

&gt; vim server/solr/new_core/conf/solrconfig.xml<!-- Request Handlershttp://wiki.apache.org/solr/SolrRequestHandlerIncoming queries will be dispatched to a specific handler by namebased on the path specified in the request.If a Request Handler is declared with startup="lazy", then it willnot 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><!-- SearchHandlerhttp://wiki.apache.org/solr/SearchHandlerFor processing Search Queries, the primary Request Handlerprovided with Solr is "SearchHandler" It delegates to a sequentof SearchComponents (see below) and supports distributedqueries across multiple shards-->

该文件的配置如下,连接的是mysql也支持其他的数据库

  • query:查询数据库表符合记录数据
  • deltaQuery:增量索引查询主键ID 注意这个只能返回ID字段
  • deltaImportQuery:增量索引查询导入的数据
&gt; 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>

在这之后,需要配置managed-schema文件,与数据库进行映射,在117行附近,添加与数据库的映射,具体添加规则,不详细写了。

&gt; 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" />

重启solr

&gt; solr restart -force

再次增加core发现已经可以增加成功

初始化数据

初始化完成就可以进行查询了

如果修改了可以触发更新操作

当然也可以通过请求URL的方式进行数据更新,这里也方便索引的更新和程序相结合

http://172.16.3.148:8983/solr/new_core/dataimport?command=delta-import&amp;clean=%20false&amp;commit=true&amp;wt=json&amp;indent=true&amp;verbose=false&amp;optimize=false&amp;debug=false

转载于:https://my.oschina.net/wenzhenxi/blog/3052333

Solr搜索引擎 — 通过mysql配置数据源相关推荐

  1. tomcat mysql数据源_Tomcat mysql 配置数据源

    把驱动拷贝到/common/lib下,然后改server.xml和web.xml, server.xml加如下(里): debug="5" reloadable="tru ...

  2. Windows下Solr的安装与配置,附DIH全量导入MySQL数据、IK分词器配置详解——不用集成Tomcat

    Solr是Apache开源的比较稳定的一款全文搜索引擎,也是市面上相对比较流行的一款全文搜索引擎,好不好用你用过之后自有判断.今天给大家分享一下它的安装与配置,我用的是7.7.2版本.废话不多说,开搞 ...

  3. .net odbc连接mysql数据库,下载安装MySQL数据库ODBC驱动和配置MySQL ODBC数据源

    1. 下载MySQL ODBC驱动: 打开的页面如下图所示,可根据实际使用情况选择下载相应的MSI安装程序,使用Visual C++ 6.0环境编程请下载32位MSI安装程序. 点击下载后出现如下页面 ...

  4. mysql 多数据源访问_通过Spring Boot配置动态数据源访问多个数据库的实现代码

    之前写过一篇博客<Spring+Mybatis+Mysql搭建分布式数据库访问框架>描述如何通过Spring+Mybatis配置动态数据源访问多个数据库.但是之前的方案有一些限制(原博客中 ...

  5. mysql-plus多数据库_Springboot+mybatisplus+mysql配置多数据源(注解版)

    1.添加依赖,最关键的两个依赖是后面两个"druid依赖"和"配置动态数据源"(已标红),其他"非主要"依赖可按自身实际开发环境进行选择. ...

  6. mysql datasource.url_SpringBoot配置数据源DataSource

    使用properties文件配置springboot默认数据源 这种方式十分简单,只用在application.properties文件中配置数据库连接属性即可. spring.datasource. ...

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

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

  8. Spring Boot使用spring-data-jpa配置Mysql多数据源

    转载请注明出处 :Spring Boot使用spring-data-jpa配置Mysql多数据源 我们在之前的文章中已经学习了Spring Boot中使用mysql数据库 在单数据源的情况下,Spri ...

  9. MySQL的ODBC驱动下载、安装以及配置数据源

    一.下载安装ODBC 1.odbc的下载地址:http://dev.mysql.com/downloads/connector/odbc/(官方下载地址) 2.进入下载界面后,不登录(Login)也不 ...

最新文章

  1. tomcat设置监听端口以及设置运行环境
  2. 2015/Province_C_C++_C/8/饮料换购
  3. BX、DI、SI、BP总结
  4. mybatis学习(42):mybatis的一级缓存
  5. 安庆机器人编程选_安庆市首届中小学机器人创客竞赛举行 460名选手比智慧拼创新 科技感满满!...
  6. #简单统计学#加权平均数
  7. 《机器视觉算法与应用》学习笔记(一)图像采集——照明
  8. LDA主题模型-TFIDF
  9. 中英文电子书下载:https://sobooks.cc/
  10. 怎么注册购买163VIP邮箱
  11. 打印机乱码不停打印_性价比高的打印机推荐【2020年9月】-十大高性价比家用/办公打印机...
  12. 什么是世界协调时间UTC
  13. 弧度和度 180/PI PI/180换算关系
  14. 目标检测之—非极大抑制(NMS)综述
  15. 大学英语四级涉及计算机阅读,大学英语四级阅读部分应试技巧 -电脑资料
  16. 文房四宝用计算机取代的什么,现代文房四宝是哪些?
  17. Navicat Premium汉化
  18. win10开启虚拟机蓝屏死机解决问题
  19. 根据子网掩码计算主机数
  20. EXCEL中把两列表格里的数字合成一列并且中间用逗号隔开

热门文章

  1. [转] Putty - 文件夹显示的蓝色太暗
  2. glup Browsersync
  3. memcpy()函数
  4. mysql查看存储过程工作记录20130711
  5. CentOS yum源
  6. 开发函数计算的正确姿势——支持 ES6 语法和 webpack 压缩
  7. 服务部署如何做到高可用?这份“三级跳”秘籍送给你\n
  8. 【Java 并发】详解 ThreadLocal
  9. Windows开发环境搭建(安装 VS2010, VS2013, VS2015 Community, Windows Server 2008 R2)
  10. Java学习笔记(5)——泛型