Mixed MySQL and Sphinx queries

送分小仙女□ 提交于 2019-12-12 05:25:12

问题


I have MySQL and Sphinx installed and working properly on a LNMP server. Now I'd like to integrate a Sphinx sub-query into an existing MySQL query.

Example:

SELECT * FROM mysql_table
JOIN (SELECT id FROM sphinx_index MATCH ('keyword')) AS match_table
ON match_table.id = mysql_table.id

Is this possible? If not, should I do the Sphinx separately and then use WHERE IN in the MySQL query, or will this kill the extra efficiency I'm getting from Sphinx?


回答1:


Use SphinxSE http://sphinxsearch.com/docs/current.html#sphinxse-overview

Then would be

SELECT * FROM mysql_table
JOIN (SELECT id FROM sphinx_index WHERE query='keyword') AS match_table
ON match_table.id = mysql_table.id

Although

SELECT * FROM sphinx_index INNER JOIN mysql_table USING (id) WHERE query='keyword'

is shorter and more concise. And better maintains the order of results.

Where 'sphinx_index' is a SphinxSE table, which points to underlying sphinx index.




回答2:


It seems I found the answer on another SO question:

Integrating Sphinx to MySQL

From reading this, it looks like Sphinx and MySQL are not as integrated as I had hoped. They need to be used on separate connections, so you can't combine queries. Oh well...



来源:https://stackoverflow.com/questions/12666322/mixed-mysql-and-sphinx-queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!