用PHP构建自定义搜索引擎

http://tech.ddvip.com   2007年09月12日    社区交流

内容摘要:虽然 Google 及其系列产品几乎无所不能,但是 Web 形式的强大搜索引擎并不能很好地适用于每个站点。如果站点内容已被高度专业化或已明确分类,那就需要使用 Sphinx 和 PHP 来创建一个优化的本地搜索系统。

  在视图中,字段 id 将指回 Inventory 表中的零件条目。partno 和 description 列是要搜索的主要文本,而 assembly 和 model 列用作进一步过滤结果的组。视图就绪后,构造数据源查询就是小事一桩。清单 7 显示了 catalog 数据源定义的其余部分。

  清单 7. 查询创建待索引的行

  # 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
}

  sql_query 必须包括后续查找需要使用的主键,并且它必须包括需要索引和用作组的所有字段。两个 sql_group_column 条目将声明 Assembly 和 Model 可用于过滤结果。并且 search 实用程序将使用 sql_query_info 来查找匹配记录。在查询中,$id 被替换为 searchd 返回的每个主键。

来源:ibm    作者:Martin Streicher    责编:豆豆技术应用

正在加载评论...