By default, the search results are ordered by score. The programmer can change this behavior by setting a sort field (or a list of fields), sort type and sort order parameters.
$index->find() call may take several optional parameters:
<?php
$index->find($query [, $sortField [, $sortType [, $sortOrder]]]
[, $sortField2 [, $sortType [, $sortOrder]]]
...);
A name of stored field by which to sort result should be passed as the
$sortField parameter.
$sortType may be omitted or take the following enumerated values:
SORT_REGULAR (compare items normally- default value),
SORT_NUMERIC (compare items numerically),
SORT_STRING (compare items as strings).
$sortOrder may be omitted or take the following enumerated values:
SORT_ASC (sort in ascending order- default value),
SORT_DESC (sort in descending order).
Examples:
<?php
$index->find($query, 'quantity', SORT_NUMERIC, SORT_DESC);
<?php
$index->find($query, 'fname', SORT_STRING, 'lname', SORT_STRING);
<?php
$index->find($query, 'name', SORT_STRING, 'quantity', SORT_NUMERIC, SORT_DESC);
Please use caution when using a non-default search order; the query needs to retrieve documents completely from an index, which may dramatically reduce search performance.




