Sorting modes

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 first
  • SPH_SORT_ATTR_DESC: Sorts by an attribute in descending order, that is, bigger attribute values first
  • SPH_SORT_ATTR_ASC: Same as SPH_SORT_ATTR_DESC, but sorts in ascending order
  • SPH_SORT_TIME_SEGMENTS: Sorts by time segments (last hour/day/week/month), in descending order, and then by relevance in descending order
  • SPH_SORT_EXTENDED: Sorts by SQL-like combination in ASC or DESC order
  • SPH_SORT_EXPR: Sorts by an arithmetic expression

Examples:

// 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'),
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset