标签:
sphinx中复合属性字段sql_attr_multi的用法 sql_attr_multi在sphinx可以用来检索有层级关系的数据,效率相当高,如,在数据库中用一个4层的分类,分类下对应着不用的文章,现在需要做一个文章列表,要求,选择第一级分类时属于它的子分类的文章也要显示出来,就可以用下面的方法建索引 sql_query= SELECT di.company_document_id as id,di.company_document_id, di.title as title_attr, di.content as content_attr, di.sort, di.weixin_company_id, di.is_show, di.mod_time, dc.category_id, dc.document_type, CONCAT(IF(dc.`category_id` is NULL,0,dc.`category_id`),‘,‘,IF(dc2.`category_id` is NULL,0,dc2.`category_id`),‘,‘,IF(dc3.`category_id` is NULL,0,dc3.`category_id`),‘,‘,IF(dc4.`category_id` is NULL,0,dc4.`category_id`)) AS category_ids FROM test_company_document di LEFT JOIN crm_company_document_category dc ON dc.category_id = di.category_id LEFT JOIN test_company_document_category dc2 ON dc.parent_id = dc2.category_id LEFT JOIN test_company_document_category dc3 ON dc2.parent_id = dc3.category_id LEFT JOIN test_company_document_category dc4 ON dc3.parent_id = dc4.category_id WHERE di.is_show =1 AND di.is_delete = 0 AND di.company_document_id>=$start AND di.company_document_id<=$end sql_query_range = SELECT MIN(company_document_id),MAX(company_document_id) FROM test_company_document sql_range_step = 1000 然后用下面的方法建立sql_attr_multi属性字段: sql_attr_multi = uint category_ids from field category_ids 生成索引后,表中的数据如下: category_ids ... 0,1,2,3 ... 0,1 ... 本文原创于phpsir的新浪博客 (phpsir的发现与总结 http://blog.sina.com.cn/phpsir),未经本人允许禁止转载。 即可用:filter=category_ids,1的方式检索在不同层级分类下的文章。 另外,也可以用下面的语法建立sql_attr_multi字段: # sql_attr_multi = uint atags from ranged-query; # SELECT d.company_document_id,da.category_name FROM test_company_document_category da # INNER JOIN test_company_document d ON d.category_id = da.category_id # WHERE d.company_document_id>=$start AND d.company_document_id<=$end ORDER BY d.company_document_id ASC; # SELECT MIN(company_document_id),MAX(company_document_id) FROM test_company_document;
sphinx中复合属性字段sql_attr_multi的用法
标签:
原文地址:http://my.oschina.net/yonghan/blog/486733