Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating Sphinx to MySQL

Tags:

mysql

sphinx

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?
like image 529
quarks Avatar asked Jul 28 '12 04:07

quarks


1 Answers

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.

http://sphinxsearch.com/docs/current.html#sphinxse

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.

like image 57
barryhunter Avatar answered Sep 18 '22 13:09

barryhunter