用sphinx sql_attr_multi mva 和filter实现SQL WHERE IN 效果

在sql_query中,取出一字段以逗号隔开的整型串 cate_ids 如:
SELECT CONCAT(IF(dc.`cate_id` is NULL,0,dc.`cate_id`),',',IF(dc2.`cate_id` is NULL,0,dc2.`cate_id`),',',IF(dc3.`cate_id` is NULL,0,dc3.`cate_id`),',',IF(dc4.`cate_id` is NULL,0,dc4.`cate_id`)) AS cate_ids
FROM mytable mt
LEFT JOIN cate dc ON dc.cate_id = mt.cate_id
LEFT JOIN cate dc2 ON dc.parent_id = dc2.cate_id
LEFT JOIN cate dc3 ON dc2.parent_id = dc3.cate_id
LEFT JOIN cate dc4 ON dc3.parent_id = dc4.cate_id

再设置sql_attr_multi属性如下:
sql_attr_multi = uint ids from field cate_ids

或直接
sql_attr_multi = uint ids from query;\
SELECT docid, cate_id FROM cate WHERE 1 ORDER BY docid ASC; \

在sphinxSE中用WHERE query='filter=ids,2345,5334' 即可实现SQL中WHERE ids IN (2345,5334)的效果。

http://www.coreseek.cn/docs/coreseek_4.1-sphinx_2.0.1-beta.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注