
常用软件类: |
|杀毒安全 | |联络聊天 | |网络软件 | |多媒体类 | |系统工具 | |图形图像 | |系统工具 | |应用软件 | |行业软件 |
开发设计类: |
|动画制作 | |图像处理 | |3D设计 | |操作系统 | |站长学院 | |网络相关 | |WEB设计 | |数据库类 | |程序开发 |
百度搜藏|
新浪VIvi|
365key|
Younote|
搜狐 |
博采中心|
你好BLOG|
亿友网摘|
网摘博客|
POCO网摘|
和讯网摘|
搜索表
定义了这些表后,就可以轻松地响应很多搜索:
·显示特定型号的所有版本
·列出装配特殊型号和版本所需的所有部件
·显示构成特定型号和版本的特殊部件的所有零件
但是很多搜索代价较大:
·查找所有模型和版本中出现零件号开头为 “WIN” 的所有零件
·查找描述中有 “lacquer” 或 “paint” 的那些零件
·查找描述中有 “black leather” 的所有零件
·查找描述中有 “paint” 的所有 2002 J 系列零件
这些搜索中的每个搜索都要求使用长篇的 JOIN 子句或代价高昂的 LIKE 子句,尤其是在 Inventory 表和 Schematic 表十分大时更是如此。而且,复杂的文本搜索完全超出了 MySQL 的能力。要搜索大量文本数据,请考虑构建和使用 Sphinx 索引。
集成 Sphinx 软件
要应用 Sphinx 来解决问题,您必须定义一个或多个数据源以及一个或多个索引。
source 将标识数据库来建立索引,提供验证信息,并且定义查询用以构造每行。数据源可以随意地标识一列或多列作为过滤器,Sphinx 将之称为组。您将使用组来过滤结果。例如,单词描述可能得到 900 个匹配。如果只对特定型号的汽车匹配感兴趣,则可以进一步使用型号组进行过滤。
index 将要求获得数据源(即一组数据行)并定义应当如何为已从数据源中提取出来的数据编目。
您将在 sphinx.conf 文件中定义数据源和索引。Body Parts 的数据源是 MySQL 数据库。清单 5 显示了名为 catalog 的数据源的部分定义 —— 指定连接的数据库以及如何建立连接(主机、套接字、用户和密码)的代码片段。
清单 5. 用于访问 MySQL 数据库的设置
| source catalog { type = mysql sql_host = localhost sql_user = reaper sql_pass = s3cr3t sql_db = body_parts sql_sock = /var/run/mysqld/mysqld.sock sql_port = 3306 |
| CREATE OR REPLACE VIEW Catalog AS SELECT Inventory.id, Inventory.partno, Inventory.description, Assembly.id AS assembly, Model.id AS model FROM Assembly, Inventory, Model, Schematic WHERE Schematic.partno_id=Inventory.id AND Schematic.model_id=Model.id AND Schematic.assembly_id=Assembly.id; |
| mysql> use body_parts; Database changed mysql> select * from Catalog; +----+---------+---------------------+----------+-------+ | id | partno | description | assembly | model | +----+---------+---------------------+----------+-------+ | 6 | 765432 | Bolt | 5 | 1 | | 8 | ENG088 | Cylinder head | 5 | 1 | | 1 | WIN408 | Portal window | 3 | 1 | | 5 | WIN958 | Windshield, front | 3 | 1 | | 4 | ACC5409 | Cigarette lighter | 7 | 3 | | 9 | ENG976 | Large cylinder head | 5 | 3 | | 8 | ENG088 | Cylinder head | 5 | 7 | | 6 | 765432 | Bolt | 5 | 7 | +----+---------+---------------------+----------+-------+ 8 rows in set (0.00 sec) |
| # indexer query # document_id MUST be the very first field # document_id MUST be positive (non-zero, non-negative) # document_id MUST fit into 32 bits # document_id MUST be unique sql_query = \ SELECT \ id, partno, description, \ assembly, model \ FROM \ Catalog; sql_group_column = assembly sql_group_column = model # document info query # ONLY used by search utility to display document information # MUST be able to fetch document info by its id, therefore # MUST contain '$id' macro # sql_query_info = SELECT * FROM Inventory WHERE id=$id } |
| index catalog { source = catalog path = /var/data/sphinx/catalog morphology = stem_en min_word_len = 3 min_prefix_len = 0 min_infix_len = 3 } |
| source catalog { type = mysql sql_host = localhost sql_user = reaper sql_pass = s3cr3t sql_db = body_parts sql_sock = /var/run/mysqld/mysqld.sock sql_port = 3306 # indexer query # document_id MUST be the very first field # document_id MUST be positive (non-zero, non-negative) # document_id MUST fit into 32 bits # document_id MUST be unique sql_query = \ SELECT \ id, partno, description, \ assembly, model \ FROM \ Catalog; sql_group_column = assembly sql_group_column = model # document info query # ONLY used by search utility to display document information # MUST be able to fetch document info by its id, therefore # MUST contain '$id' macro # sql_query_info = SELECT * FROM Inventory WHERE id=$id } index catalog { source = catalog path = /var/data/sphinx/catalog morphology = stem_en min_word_len = 3 min_prefix_len = 0 min_infix_len = 3 } searchd { port = 3312 log = /var/log/searchd/searchd.log query_log = /var/log/searchd/query.log pid_file = /var/log/searchd/searchd.pid } |
底部的 searchd 部分将配置 searchd 守护程序本身。该部分中的条目不言自明。query.log 尤为有用:它将在运行时显示每次搜索并显示结果,例如搜索的文档数和匹配总数。