0
我有一個獅身人面像索引表與ID,數據和數據類型。如何使用Group By和Group_Concat進行Sphinxsearch?
| sphinxid | objectid | data | type |
|----------------|----------------|----------------|-------------|
| 1 | 10 | Lorem ipsum | title |
|----------------|----------------|----------------|-------------|
| 2 | 10 | dolor si ipsum | description |
|----------------|----------------|----------------|-------------|
| 3 | 20 | dolor sit amet | date |
現在我嘗試運行與此類似工作MySQL查詢搜索查詢:
SELECT objectid, GROUP_CONCAT(type) AS types
FROM SphinxIndex
WHERE data LIKE '%ipsum%'
GROUP BY objectid
下面是使用sphinxapi.php
$cl = new SphinxClient();
$cl->SetServer("localhost", 9312);
$cl->SetMatchMode(SPH_MATCH_EXTENDED);
$cl->SetLimits(0, 1000);
$cl->SetRankingMode(SPH_RANK_SPH04);
// THROWS ERR: can not aggregate non-scalar attribute 'datatype'
$cl->SetSelect("objectid, GROUP_CONCAT(type) AS types");
//----------------------------------------------
$cl->SetGroupBy('objectid', SPH_GROUPBY_ATTR, '@count DESC');
$cl->SetSortMode(SPH_SORT_EXTENDED, "@count DESC");
$searchresults = $cl->Query('*' . 'ipsum' . '*');
我預期的結果是什麼我的PHP代碼像這樣,
| objectid | types |
|----------------|--------------------|
| 10 | title, description |
但不幸的是它拋出一個錯誤:
THROWS ERR: can not aggregate non-scalar attribute 'type'
,我讀了多值屬性可能是問題的一個可能的解決方案,但我沒有真正明白這是怎麼工作的。
什麼是'datatype'?我沒有看到你的表中有任何數據類型。 – akond
它的一個錯字 - 在我真正的索引表中該列被命名爲數據類型。編輯它 – steedz