Book Image

Sphinx Search Beginner's Guide

By : Abbas Ali
Book Image

Sphinx Search Beginner's Guide

By: Abbas Ali

Overview of this book

Table of Contents (15 chapters)
Sphinx Search
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface

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-&gt...