第一次使用Sphinx——配置sql_query键
我目前正在练习使用 Sphinx,除了我想要做的配置之外,我还没有做太多事情。 sql_query
键让我有点困惑该放什么,我在 Sphinx sql_query 的文档 但它似乎并没有让我清楚该做什么,因为我的 Web 应用程序中有很多 SELECT,并且我想使用 Sphinx 进行搜索和 SQL经常是更改(根据用户搜索过滤)。
当我使用 MySQL 进行搜索时,我想将 Sphinx 集成到我的 Web 应用程序中,如果 sql_key 不是可选的,我是否必须将整个搜索 SQL 查询放入该字段,或者我选择从表中取出必要的字段来开始重新索引?
有人可以为我指明正确的方向,以便我可以顺利使用 Sphinx 和我的 Web 应用程序吗?
I'm currently practicing using Sphinx, I've not far off done much, except the configuration what I'm trying to do. The sql_query
key is leaving me somewhat confused what to put there, I read in the Sphinx documentation of sql_query but it doesn't seem to clear my mind from knowing what to do since I have many SELECTs in my web application, and I want to use Sphinx for my search and the SQL is often changed (upon user search filtering).
As of my search using MySQL, I want to integrate Sphinx to my web application, if the sql_key
is not optional, do I have to expect to put the whole search SQL query into that field or do I pick out the necessary fields from tables to start a reindex?
Can someone point me to the right direction so I can get things going well with Sphinx and my web application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
sql_query 是强制性的,它由 sphinx 运行以从 mysql 获取要索引的数据。你可以有连接、条件等,必须是有效的sql查询。您应该有类似“SELECT id ,field1,field2,fieldx from table”的内容。 id 必须是主 id。此查询返回的每一行都被视为一个文档(在您搜索时由 sphinx 返回)。
如果您有多个表(含义非常不同 - 用户、文章等) - 您需要为每个表创建一个索引。
从此处阅读教程:http://sphinxsearch.com/info/articles/ 了解 sphinx 的工作原理。
sql_query is mandatory , it's run by sphinx to get the data you want to be indexed from mysql . You can have joins , conditions etc. , must be a valid sql query . You should have something like "SELECT id ,field1,field2,fieldx from table" . id must be a primary id .Each row returned by this query is considered a document ( which is returned by sphinx when you search ) .
If you have multiple tables ( that are very different by meaning - users , articles etc.) - you need to create an index for each .
Read tutorials from here : http://sphinxsearch.com/info/articles/ to understand how sphinx works .
您可以创建一个 sql 查询来从数据库中获取记录的并集。如果您进行多个表连接并查询以选择最佳结果集,您也可以使用 Sphinx 来完成。
数据库中现有的表结构可能会遇到一些问题。
例如:
基表没有整数主键字段
创建一个包含两个字段的新表。一个用于整数 id 字段,另一个字段用于保存基表的主键。与该表进行内部联接并从该表中选择 id 字段。
例如。
从 table_new t1 INNER JOIN table_2 t2 WHERE t1.document_id = t1.thread_id INNER JOIN REST_OF_YOUR_SELECT_QUERY 中选择 t1.id、t2.name、t2.description、t2.content
ta.id用于Sphinx搜索引擎进行内部索引。
您可以通过放置 WHERE 子句并进行过滤来过滤数据
您可以在 Sphinx 中根据条件动态设置过滤器来实现此目的。
您选择并连接不同的表以获得结果
这也可以通过根据您的要求设置不同的源和索引来完成。
希望这能帮助您了解需要添加和修改的内容,以开始思考如何根据您的要求配置 Sphinx 搜索引擎。如果您需要更多帮助,请再次来到这里。
You can create a sql query to get union set of records from the Database. If you do multiple table joining and query to select the best result set, you can do it with Sphinx too.
You may run into a few trouble with your existing table structure in the database.
Like :
Base table does not have integer primary key field
Create a new table which has two fields. One for the integer id field and the other field to hold the primary key of the base table. Do an inner join with that table and select the id field from that table.
Eg.
SELECT t1.id, t2.name, t2.description, t2.content FROM table_new t1 INNER JOIN table_2 t2 WHERE t1.document_id = t1.thread_id INNER JOIN REST_OF_YOUR_SELECT_QUERY
The ta.id is for Sphinx search engine to do its internal indexing.
You filter data by placing WHERE clause and filtering
You can do that in Sphinx by setting filters dynamically based on the conditions.
You select and join different tables to get results
This also can be done by setting different sources and indexes based on your requirements.
Hope this would help you to get an understanding what you need to add and modify to start thinking how Sphinx search engine can be configured to your requirements. Just come here again if your need more help.