Answer the question
In order to leave comments, you need to log in
How to sort sphinx by value?
Hello!
Is it possible to sort search results by attribute value, i.e. so that the goods I need go first.
Tried to do through multiple queries:
$cl->SetLimits(0, 12);
$cl->SetFilter ('category', array(crc32('Готовые изделия')));
$cl->AddQuery('@name '.$_GET['search']);
$cl->ResetFilters();
$cl->SetSortMode (SPH_SORT_ATTR_DESC, 'category');
$cl->SetFilter ('category', array(crc32('Готовые изделия')), true);
$cl->AddQuery('@name '.$_GET['search']);
$result = $cl->RunQueries();
Answer the question
In order to leave comments, you need to log in
In your example, two queries are obtained, you need to build one query.
Try using SetSelect for the desired category to set the value to 1, and for the rest to 0.
In SetSortMode SPH_SORT_EXTENDED sort by the value from SetSelect and by the category attribute.
This will result in a single query that fetches products from a specific category first.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question