测试ubuntu安装sphinx及配置集成到magento产品搜索



测试ubuntu安装sphinx及配置集成到magento产品搜索本机的测试环境为ubuntu版本为13.10, 目的是为magento产品搜索集成sphinx

 

直接

sudo apt-get install sphinxsearch

就安装成功了, 哈,简单吧…

装是装了, 怎么用呢?

whereis sphinxsearch

找到sphinx的路径,默认在 /etc/sphinxsearch

cd /etc/sphinxsearch

sphinx.conf.sample 有详细说明配置文件的各参数作用

sphinx-min.conf.dist是一个测试的模板文件了,

cp sphinx-min.conf.dist sphinx.conf

我的sphinx.conf配置如下 ,注意修改 sql连接的相关信息, 那段sql_query是怎么来的? 你就在magento搜索的collection打印一下它的sql,把它COPY过来,再select 你要的字段.

 

[plain] view plaincopy在CODE上查看代码片派生到我的代码片

  1. #
  2. # Minimal Sphinx configuration sample (clean, simple, functional)
  3. #
  4. source src1
  5. {
  6.     type                    = mysql
  7.     sql_host                = localhost
  8.     sql_user                = root
  9.     sql_pass                = 123456
  10.     sql_db                  = magentodb
  11.     sql_port                = 3306  # optional, default is 3306
  12.     sql_query               =SELECT `e`.`entity_id`,`e`.`sku`, `_table_short_descrip_default`.value AS `short_description`,`_table_titile`.value AS `title`,`_table_descrip_default`.value AS `description` FROM `catalog_product_entity` AS `e` LEFT JOIN `catalog_product_entity_text` AS `_table_short_descrip_default` ON (_table_short_descrip_default.entity_id = e.entity_id) AND (_table_short_descrip_default.attribute_id = (select attribute_id from eav_attribute where attribute_code=’short_description’ and entity_type_id=(select entity_type_id from  eav_entity_type where entity_model=’catalog/product’))) LEFT JOIN `catalog_product_entity_varchar` AS `_table_titile` ON (_table_titile.entity_id = e.entity_id) AND (_table_titile.attribute_id = (select attribute_id from eav_attribute where attribute_code=’name’ and entity_type_id=(select entity_type_id from  eav_entity_type where entity_model=’catalog/product’))) LEFT JOIN `catalog_product_entity_text` AS `_table_descrip_default` ON (_table_descrip_default.entity_id = e.entity_id) AND (_table_descrip_default.attribute_id=(select attribute_id from eav_attribute where attribute_code=’description’ and entity_type_id=(select entity_type_id from  eav_entity_type where entity_model=’catalog/product’)))LEFT JOIN `catalog_product_entity_int` AS `_table_status_default` ON (_table_status_default.entity_id = e.entity_id) AND (_table_status_default.attribute_id=(select attribute_id from eav_attribute where attribute_code=’status’ and entity_type_id=(select entity_type_id from  eav_entity_type where entity_model=’catalog/product’))) where `_table_status_default`.value=1
  13.     sql_attr_uint           = group_id
  14.     sql_attr_timestamp      = date_added
  15. #   sql_query_info          = SELECT * FROM documents WHERE id=$id
  16. }
  17. index test_magento
  18. {
  19.         source                                 = src1
  20.         path                    = /var/lib/sphinxsearch/data/test_magento
  21.         docinfo                                 = extern
  22.         charset_type                    = utf-8
  23. }
  24. indexer
  25. {
  26.     mem_limit       = 256M
  27. }
  28. searchd
  29. {
  30.     listen          = 9312
  31.     listen          = 9306:mysql41
  32.     log         = /var/log/sphinxsearch/searchd.log
  33.     query_log       = /var/log/sphinxsearch/query.log
  34.     read_timeout        = 5
  35.     max_children        = 30
  36.     pid_file        = /var/run/sphinxsearch/searchd.pid
  37.     max_matches     = 1000
  38.     seamless_rotate     = 1
  39.     preopen_indexes     = 1
  40.     unlink_old      = 1
  41.     workers         = threads # for RT to work
  42.     binlog_path     = /var/lib/sphinxsearch/data
  43. }


 

 

写完配置文件,要生成索引

sudo indexer –config /etc/sphinxsearch/sphinx.conf –all

注意config,all前是两个横

indexer,search,searchd是sphinxsearch安装后就有的了,如果你是源码安装,会在对应目录的bin下

最后你要测试一下,

sudo search –config /etc/sphinxsearch/sphinx.conf “你要找的产品关键字”

如果你没有注释了sql_query_info                  = SELECT * FROM documents WHERE id=$id

是会报错的, 因为你的数据库中没有这个documents表, 可以看一下/etc/sphinxsearch/example.sql 有一个建这个表的sql ,

启用服务

sudo searchd –config /etc/sphinxsearch/sphinx.conf

好了,这样就可以了, 至于magento如何集成sphinx, 就去找一个插件罗,如果你是极客,喜欢自己写, 主要是重写CatalogSearch_Block_Result

加油!