如何为狮身人面像创建正确的索引

时间:2015-08-28 11:37:54

标签: sphinx

我有桌子:

product 
| id | shop_id | name |
| 1  |  1      | p1   |
| 2  |  1      | p2   |
| 3  |  2      | p3   |
etc

shop
| id | name |
| 1  | s1   |
| 2  | s2   |
| 3  | s3   |
| 4  | s4   |
etc

country
| id | name   |
| 1  | russia |
| 2  | usa    |
etc

shop_country
|id | shop_id | country_id |
| 1 | 1       |   1        |
| 2 | 1       |   2        |
| 3 | 2       |   1        |

我需要获得在一个国家/地区提供的商品。

来自mysql的工作请求:

SELECT *
FROM product AS p
LEFT JOIN shop_country sc ON (p.shop_id = sc.shop_id)
WHERE product.status = 1 mc.country_id = 3

我创建了一个索引:

SELECT product.id as id, product.shop_id \
FROM product \
LEFT JOIN shop_country sc ON (product.shop_id = sc.shop_id) \                                
GROUP BY product.id

但它会产生错误的结果

在Sphinx中我需要做什么?

1 个答案:

答案 0 :(得分:1)

GROUP BY product.id 

表示您拥有相同产品的多个国家/地区

SELECT product.id as id, product.shop_id \

没有群组功能

所以用

代替
SELECT product.id as id, group_concat(product.shop_id)  \

并尝试设置 shop_id为sql_attr_multi