0

所以我的 sphinx.conf 文件包含类似的内容。基本上我正在使用增量索引来使事情变得更快。

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
}

在 php 中,当我检索数据时,我还希望有某种排序方法。

$s->SetSortMode(SPH_SORT_EXTENDED, '@relevance DESC, total_likes DESC, @id DESC');
$result = $s->Query($data['query'], "delta main");

当我只有main索引时,排序工作正常。但是现在当我使用两个索引进行搜索时,增量索引的结果会附加在前面。我真正想要的是从两个索引中获取结果,然后根据偏好进行排序,即@relevance DESC, total_likes DESC, @id DESC在我的情况下。那total_likes应该优先于id

4

1 回答 1

0

感谢@barryhunter解决方案。解决方案是在增量索引中第二个 sql_query_pre 必须被覆盖。

sql_query_pre = SET NAMES utf8
    sql_query_pre =
    sql_query = \
于 2013-06-21T13:13:42.100 回答