测试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 你要的字段.

#
# Minimal Sphinx configuration sample (clean, simple, functional)
#


source src1
{
	type					= mysql

	sql_host				= localhost
	sql_user				= root
	sql_pass				= 123456
	sql_db					= magentodb
	sql_port				= 3306	# optional, default is 3306

	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

	sql_attr_uint			= group_id
	sql_attr_timestamp		= date_added

#	sql_query_info			= SELECT * FROM documents WHERE id=$id
}

index test_magento
{
        source	                               = src2
        path                    = /var/lib/sphinxsearch/data/test_magento
        docinfo                                 = extern
        charset_type                    = utf-8
}

indexer
{
	mem_limit		= 256M
}


searchd
{
	listen			= 9312
	listen			= 9306:mysql41
	log			= /var/log/sphinxsearch/searchd.log
	query_log		= /var/log/sphinxsearch/query.log
	read_timeout		= 5
	max_children		= 30
	pid_file		= /var/run/sphinxsearch/searchd.pid
	max_matches		= 1000
	seamless_rotate		= 1
	preopen_indexes		= 1
	unlink_old		= 1
	workers			= threads # for RT to work
	binlog_path		= /var/lib/sphinxsearch/data
}

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

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

加油!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值