sphinx连接mysql,将Sphinx集成到MySQL

I am trying to use Sphinx full-text search capability for my MySQL server.

I have setup a local Sphinx service based on the installation manual and able to do text search.

I can connect to

mysql.exe --host=127.0.0.1 port=9306

Where the port 9306 is the port configured in sphinx.conf:

searchd {

...

listen = 9306:mysql41

...

}

And do SphinxQL queries. I am using the default Sphinx example database shipped with the release package.

However I want to integrate Sphinx with my MySQL server, such that all the clients connecting to my sql server can do SphinxQL and I want to try it out with the MySQL sample database sakila

What are the steps to achieve that?

Do I need to convert the database engine from InnoDB to Sphinx?

Also, from what it seems, Sphinx can only index one (1) database

table per configuration, how can I make sure that all tables in the

MySQL database gets indexed?

解决方案

However I want to integrate Sphinx with my MySQL server, such that all the clients connecting to my sql server can do SphinxQL

Can't do that. Sphinx (when enabled for sphinxQL) just gives you a server that looks like a mysql one - ie it uses the same communications protocol - mainly so can just reuse mysql client libraries, rather than having to make a new one just for sphinx.

They are different 'servers'. You connect to a mysql server to run mysql commands; you connect to sphinx server to run sphinxQL commands.

The application woudl have to connect to each 'server' seperately. Just imagine sphinx was something like postgres, you clearly dont connect to mysql and expect to be able to run postgresql.

However there is SphinxSE - which is a fake mysql storage engine. You install it into mysql, and you can then create a table using this engine. Then you run mysql queries against this table, under the hood are contacts a running sphinx-server. So to mysql it looks like a table that contains data, this is most useful because can then 'join' this search table with the original data table to get results and the original data in one mysql query.

The application then doesn't have to connect to sphinx itself. SphinxSE does it for you.

Do I need to convert the database engine from InnoDB to Sphinx?

No. You keep the original data where it is, using what ever engine you like. Sphinx just provides an 'index' - it doesnt store the original data*. Its not a database as such, just provides for fast quering with its highly optimized indexing.

Basically you ask sphinx for the unique id's of documents matching a certain query. Then use those ids to lookup the data. SphinxAPI, sphinxSE and sphinxQL are just three different mechanisms of doing that.

Also, from what it seems, Sphinx can only index one (1) database table per configuration,

No. A single sphinx instance can host many indexes. And an index can have many sources. So can just create one index per table. Or if you mainly want to search them together, can just create one amalgamated index.

--

** Edit to reply to question in comments: **

When you say that, sphinx can host many indexes, is it relying solely in the sphinx.conf configuration file?

You would probably define one sphinx index per table. So you would need a source/index pair for each table. (unless you wanted to index all tables in one index, whihch is possible too.

It cant read the tables itself, and create config file, you have to define each index individually.

When you say "gives you a server that looks like a mysql one" do you mean like a proxy,

No. Not a proxy.

where my MySQL client can connect to this Sphinx port and the client will think that its a MySQL server?

Basically yes. The client will connect to it the same way it connects to a mysql-server.

If so, then I can execute both MySQL SQL queries and also SphinxQL at the same connection?

No. Impossible. Connect to mysql-server, to run mysql queries. Connect to searchd to run sphinxQL queries.

Two connections, one per server.

why my MySQL Workbench can't connect to port 9306,

Don't know. Might be a firewall issue.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、XX网搜索引擎架构设计: 3 1、搜索引擎架构图(基于PHP+MySQL+Sphinx): 3 2、搜索引擎架构设计思路: 3 ⑴、调用方式最简化: 3 ⑵、创建索引、查询速度快: 3 ⑶、按服务类型进行分离: 4 ⑷、“主索引+增量索引”更新方式: 4 ⑸、“Ext3文件系统+tmpfs内存文件系统”相结合: 4 ⑹、中文分词词库: 5 二、MYSQL+SPHINX+SPHINXSE安装步骤: 5 1、安装python支持 5 2、编译安装LibMMSeg 5 3、编译安装MySQL 5.1.26-rc、SphinxSphinxSE存储引擎 5 4、创建Sphinx索引文件和MySQL数据文件存放目录 6 5、创建MySQL配置文件(以线上配置文件为准) 6 ⑴、创建配置文件/mysql/3306/my.cnf(以db11的3306端口为例) 6 ⑵、创建配置文件/mysql/3406/my.cnf(以db11的3406端口为例) 8 6、制作一份MySQL Slave供搜索引擎使用 10 7、创建快捷启动、停止、重启、杀死MySQL进程的脚本(以db11的3306端口为例) 10 三、SPHINX配置: 11 1、生成Sphinx中文分词词库 11 ⑴、词典的构造 12 ⑵、词典文件格式 12 ⑶、XX网搜索引擎的中文分词词库 12 2、创建Sphinx主索引文件、增量索引文件存放目录 12 3、创建Sphinx配置文件 13 4、初始化sphinx.conf中配置的全部索引 13 5、创建两个shell脚本,一个用来创建主索引、一个用来创建增量索引。 13 ⑴、主索引更新脚本 13 ①、创建脚本build_main_index.sh: 13 ②、赋予主索引更新脚本可执行权限: 13 ③、每天凌晨定时重建主索引: 13 ⑵、增量索引更新脚本 13 ①、创建脚本build_delta_index.sh: 13 ②、赋予增量索引更新脚本可执行权限: 14 ③、每3分钟自动重建一次搜索引擎的增量索引: 14 6、启动Sphinx守护进程(searchd) 14 7、配置服务器开机启动时需要自动执行的命令(以db11为例) 14 8、创建Sphinx存储引擎表: 14 ⑴、设置/etc/hosts 14 ⑵、登录运行在3306端口的MySQL服务器(提供“搜索查询服务”): 14 ⑶、创建数据库“Sphinx”和相对应的Sphinx表(SQL语句): 15 示例SQL: 15 四、如何通过SQL语句调用搜索引擎: 15 1、搜索应用实例 15 ⑴、XX网北京出租房搜索 15 ⑵、XX网北京小区搜索 15 ⑶、在指定字段中搜索(例如在字段“title”中搜索关键字“中关村”) 16 2、SphinxSE存储引擎及SQL语法详细说明 16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值