如何对 sphinx/php 中的结果进行排序?
How to sort results in sphinx/php?
我的索引中有优先级列。我想按优先级 DESC 获取自动建议,但它不起作用
$cl->SetMatchMode(SPH_MATCH_EXTENDED2);
$cl->SetSortMode(SPH_SORT_EXTENDED, 'priority DESC');
$cl->SetLimits(0, 10);
$cl->SetGroupBy('alias_seq', SPH_GROUPBY_ATTR);
$partialQueryStr = " @keyword ^$query*";
$cl->AddQuery($partialQueryStr, 'autosuggest');
$result = $cl->RunQueries();
狮身人面像指数
source autosuggest {
//..other fields/attrs
sql_attr_uint = priority
}
请注意,您还有 GROUP BY。在 GROUP BY 查询中,SetSortMode
设置组内顺序(即返回组中的哪一行)——而不是最终结果集。
...您需要第三个参数 ($groupsort
) 到 SetGroupBy
http://sphinxsearch.com/docs/current.html#api-func-setgroupby
Note that it's $groupsort that affects the order of matches in the final result set. Sorting mode (see Section 9.3.3, “SetSortMode”) affect the ordering of matches within group, ie. what match will be selected as the best one from the group. So you can for instance order the groups by matches count and select the most relevant match within each group at the same time.
例如:
$cl->SetGroupBy('alias_seq', SPH_GROUPBY_ATTR, 'priority DESC');
(注意它只接受一个扩展的排序参数,所以你现有的排序可以被复制)
我的索引中有优先级列。我想按优先级 DESC 获取自动建议,但它不起作用
$cl->SetMatchMode(SPH_MATCH_EXTENDED2);
$cl->SetSortMode(SPH_SORT_EXTENDED, 'priority DESC');
$cl->SetLimits(0, 10);
$cl->SetGroupBy('alias_seq', SPH_GROUPBY_ATTR);
$partialQueryStr = " @keyword ^$query*";
$cl->AddQuery($partialQueryStr, 'autosuggest');
$result = $cl->RunQueries();
狮身人面像指数
source autosuggest {
//..other fields/attrs
sql_attr_uint = priority
}
请注意,您还有 GROUP BY。在 GROUP BY 查询中,SetSortMode
设置组内顺序(即返回组中的哪一行)——而不是最终结果集。
...您需要第三个参数 ($groupsort
) 到 SetGroupBy
http://sphinxsearch.com/docs/current.html#api-func-setgroupby
Note that it's $groupsort that affects the order of matches in the final result set. Sorting mode (see Section 9.3.3, “SetSortMode”) affect the ordering of matches within group, ie. what match will be selected as the best one from the group. So you can for instance order the groups by matches count and select the most relevant match within each group at the same time.
例如:
$cl->SetGroupBy('alias_seq', SPH_GROUPBY_ATTR, 'priority DESC');
(注意它只接受一个扩展的排序参数,所以你现有的排序可以被复制)