【发布时间】:2011-06-09 03:08:33
【问题描述】:
我需要一些关于 Sphinx MySql 索引分组的帮助。
我有一个产品表,其中有产品 ID 和相应的零售商 ID。我想做的是创建一个简单的列表来显示零售商的名称以及表格中有多少产品:
标准SQL:从tblproducts中选择retailerid,count(productid)as cnt 狮身人面像:从零售商 ID 的 tblproducts1 组中选择 *
我正在使用 Sphinx 2.0.1-beta
我想使用Sphinx的原因是,因为产品的数量会被一个复杂的匹配全文查询,产品名称和描述等过滤掉。
现在我的问题是,如何从 Sphinx 返回的结果中获取这些数字/ID?当我使用 php 来显示结果时,我希望有人可以向我展示一些有用的 php 代码来从结果集中提取这些数字。 Sphinx 返回的结果数组让我更加困惑;我在任何地方都没有看到对产品数量的任何引用!
我确信 Sphinx 会返回这些数字,因为它支持分组和计数,但是如何从结果集中提取数字?
以下是我的配置文件:
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
更新
我希望如此,但我没有在下面的结果集中看到要计数的引用。我一定在某个地方犯了一些错误:
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 )
)
)
【问题讨论】:
-
您似乎是通过 API 而不是 SphinxQL 查询索引。本地与分布式索引、空选择列表等可能存在不同的情况。如果没有完整的示例,例如配置、查询索引的脚本,很难提出建议。