2011-06-09 48 views
0

我需要一些Sphinx MySql索引组的帮助。如何通过结果集中的数字提取狮身人面像组?

我有一个产品表,我有产品ID和相应的零售商ID。我想要做的是创建一个简单的列表来显示零售商的名称以及它在表格中有多少产品:

标准SQL:选择零售商,计数(productid)作为cnt来自tblproducts Sphinxs:select *从tblproducts1组由retailerid

我使用的狮身人面像2.0.1-β

我想用狮身人面像的原因是,由于产品数量将一个复杂的比赛全文查询进行过滤,对产品名称和说明等

现在我的问题是,我如何得到这些nu Sphinx返回结果中的mbers/id?正如我使用PHP来显示结果,我想如果有人可以告诉我一些有用的PHP代码从结果集中提取这些数字。狮身人面像返回的结果数组令我更加困惑;我没有看到任何地方提及任何产品!

我相信Sphinx会返回这些数字,因为它支持group by和count,但是如何从结果集中提取数字?

下面是我的配置文件:

sql_query  = \ 
    SELECT ProductId, ProductName, ProductModel, ProductDesc, ProductManf, ProductHeader, \ 
    ProductPrice, ProductPrePrice, ProductFetchDate, m.MerchantId, m.MerchantActive FROM tblproducts p \ 
    inner join tblmerchantlist m on p.MerchantId=m.MerchantId 


sql_attr_uint  = MerchantActive 
sql_attr_float  = ProductPrice 
sql_attr_float  = ProductPrePrice 
sql_group_column = MerchantId 

sql_query_info  = SELECT * FROM tblproducts WHERE ProductId=$id 

UPDATE

我希望这样,但我没有看到参考下面的结果集数。我必须做的地方一些错误:

Array ([error] => [warning] => [status] => 0 [fields] => 
    Array ([0] => productname [1] => productmodel [2] => productdesc [3] => productmanf [4] => productheader [5] => productfetchdate) [attrs] => 
    Array ([productprice] => 5 [productpreprice] => 5 [merchantid] => 1 [merchantactive] => 1) [matches] => 
    Array ([0] => 
    Array ([id] => 694173 [weight] => 396305 [attrs] => 
    Array ([productprice] => 1568.48999023 [productpreprice] => 0 [merchantid] => 12 [merchantactive] => 1)) [1] => 
    Array ([id] => 901921 [weight] => 396305 [attrs] => 
    Array ([productprice] => 1533.48999023 [productpreprice] => 1536.98999023 [merchantid] => 12 [merchantactive] => 1)) [2] => 
    Array ([id] => 302573 [weight] => 249249 [attrs] => 
    Array ([productprice] => 1059.98999023 [productpreprice] => 0 [merchantid] => 12 [merchantactive] => 1)) [3] => 
    Array ([id] => 302579 [weight] => 249249 [attrs] => 
    Array ([productprice] => 1179.98999023 [productpreprice] => 0 [merchantid] => 12 [merchantactive] => 1)) [4] => 
    Array ([id] => 302592 [weight] => 249249 [attrs] => 
    Array ([productprice] => 1429.48999023 [productpreprice] => 0 [merchantid] => 12 [merchantactive] => 1)) [5] => 
    Array ([id] => 302595 [weight] => 249249 [attrs] => 
    Array ([productprice] => 1592.98999023 [productpreprice] => 0 [merchantid] => 12 [merchantactive] => 1)) [6] => 
    Array ([id] => 302597 [weight] => 249249 [attrs] => 
    Array ([productprice] => 1129.98999023 [productpreprice] => 0 [merchantid] => 12 [merchantactive] => 1)) [7] => 
    Array ([id] => 406798 [weight] => 249249 [attrs] => 
    Array ([productprice] => 2419.98999023 [productpreprice] => 0 [merchantid] => 12 [merchantactive] => 1)) [8] => 
    Array ([id] => 407480 [weight] => 249249 [attrs] => 
    Array ([productprice] => 1287.48999023 [productpreprice] => 0 [merchantid] => 12 [merchantactive] => 1)) [9] => 
    Array ([id] => 693715 [weight] => 249249 [attrs] => 
    Array ([productprice] => 1234.98999023 [productpreprice] => 0 [merchantid] => 12 [merchantactive] => 1))) [total] => 29301 [total_found] => 29301 [time] => 0.137 [words] => 
    Array ([select] => 
     Array ([docs] => 390 [hits] => 462) [from] => 
     Array ([docs] => 4332 [hits] => 4637) [tblproducts1] => 
     Array ([docs] => 0 [hits] => 0) [where] => 
     Array ([docs] => 395 [hits] => 448) [match] => 
     Array ([docs] => 108 [hits] => 111) [cyberpowerpc] => 
     Array ([docs] => 66 [hits] => 132) [gamer] => 
     Array ([docs] => 307 [hits] => 715) [xtreme] => 
     Array ([docs] => 410 [hits] => 725) [1310lq] => 
     Array ([docs] => 2 [hits] => 6) [in] => 
     Array ([docs] => 16196 [hits] => 19786) [canada] => 
     Array ([docs] => 1146 [hits] => 1200) [group] => 
     Array ([docs] => 5716 [hits] => 5732) [by] => 
     Array ([docs] => 2143 [hits] => 2289) [merchantid] => 
      Array ([docs] => 0 [hits] => 0) 
    ) 
) 
+0

看来你通过API不SphinxQL查询索引。本地vs分布式索引,空选择列表等可能有不同的情况。很难建议没有完整的例子,即配置,脚本,查询索引。 – 2011-06-10 10:53:04

回答

0

还有就是添加到您的结果集为查询魔法属性@count

select * from tblproducts1 group by retailerid 

在结果集中的属性列表看起来像

id, weight, MerchantActive, ... @groupby, @count 

如果在searchd部分中使用compat_sphinxql_magic = 0选项,则您已明确定义并别名了所有必需的属性,如

select *, weight(*) as w, count(*) as c from tblproducts1 group by retailerid 

在结果集中的属性列表看起来像

id, MerchantActive, ... w, c