Z
Z
zeddicus2014-07-25 16:25:36
PHP
zeddicus, 2014-07-25 16:25:36

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();

By the way, with such a request in the logs, I see this:
49dde5e9f3a0458590d912538983db75.png
although judging by the description it should be like this:
[Sun Jul 12 15:18:17.000 2009] 0.040 sec x2 [ext2/0/ext 747541 (0.20)] [lj] the , i.e. it turns out at me requests are not united?
Maybe I'm doing something wrong, because this option is not suitable, since I should have 12 products on the page, but with such a request, as a result of each request, I will have 12 products, and I will only need to display 12 products from the first request, i.e. when you go to the next page, the products from the second request will not be shown.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Micher, 2014-08-04
@zeddicus

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 question

Ask a Question

731 491 924 answers to any question