At times you might want to sort the results by values other than relevance. The Sphinx API provides SetSortMode($mode, $sortby="")
method which can be used to set the sort mode other than relevance, which is the default sort mode.
The following sorting modes are available in Sphinx:
SPH_SORT_RELEVANCE:
Sorts by relevance in descending order, that is, best matches firstSPH_SORT_ATTR_DESC:
Sorts by an attribute in descending order, that is, bigger attribute values firstSPH_SORT_ATTR_ASC:
Same as SPH_SORT_ATTR_DESC
, but sorts in ascending orderSPH_SORT_TIME_SEGMENTS:
Sorts by time segments (last hour/day/week/month), in descending order, and then by relevance in descending orderSPH_SORT_EXTENDED:
Sorts by SQL-like combination in ASC
or DESC
orderSPH_SORT_EXPR:
Sorts by an arithmetic expression// Sort by relevance. Second parameter is not required in this case. $client->SetSortMode(SPH_SORT_RELEVANCE); // Sort by author_id in descending order $client->SetSortMode(SPH_SORT_ATTR_DESC, 'author_id'), // Sort by time segments i.e. first the results // will be sorted based on publish date and then on relevance. $client->SetSortMode(SPH_SORT_TIME_SEGMENTS, 'publish_date'), // Extended sort: Sort by weight desc and id asc which // is same as sorting by relevance $client->SetSortMode(SPH_SORT_EXTENDED, '@weight DESC, @id ASC'), // Sort by category_id desc and weight asc $client->SetSortMode(SPH_SORT_EXTENDED, 'category_id DESC @weight ASC'),