所以我的sphinx.conf文件包含类似的东西。基本上我使用delta索引来快速制作。
source main
{
#...
sql_query_pre = SET NAMES utf8
sql_query_pre = REPLACE INTO sph_counter SELECT 1, MAX(id) FROM photo
sql_query = \
SELECT p.id AS id, p.search AS search, COUNT(li.id) AS total_likes \
FROM `photo` p \
LEFT JOIN `like` li \
ON p.id = li.photo_id \
WHERE p.id <= ( SELECT max_doc_id FROM sph_counter WHERE counter_id=1 ) \
GROUP BY \
p.id
#...
sql_query_info = SELECT * FROM photo WHERE id=$id
}
source delta : main
{
sql_query_pre = SET NAMES utf8
sql_query = \
SELECT p.id AS id, p.search AS search, COUNT(li.id) AS total_likes \
FROM `photo` p \
LEFT JOIN `like` li \
ON p.id = li.photo_id \
WHERE p.id > ( SELECT max_doc_id FROM sph_counter WHERE counter_id=1 ) \
GROUP BY \
p.id
}
在我检索数据的时候,我也希望有一些排序方法。
$s->SetSortMode(SPH_SORT_EXTENDED, '@relevance DESC, total_likes DESC, @id DESC');
$result = $s->Query($data['query'], "delta main");
当我只有main
索引时,排序工作正常。但是现在当我使用两个索引进行搜索时,delta索引的结果会附加在前面。我真正想要的是两个索引的结果被提取然后根据偏好排序,即在我的情况下@relevance DESC, total_likes DESC, @id DESC
。 total_likes
应优先于id
答案 0 :(得分:0)
感谢@barryhunter solution。解决方案是在delta索引中第二个sql_query_pre必须被覆盖。
sql_query_pre = SET NAMES utf8
sql_query_pre =
sql_query = \