i have been trying to sort alias field defined in the setselect method as below, but it is returning irrelevant records,
SetSelect sphinx query in Nested IF Condition
$sphinxObj->SetSelect("*, IF(CityId>2 AND CityId<10,1,IF(CityId>12 AND CityId<20,2,IF(CityId>22 AND CityId<30,3,IF(CityId>33 AND CityId<40,4,0)))) as Rank");
Below are Rank values, that cannot able to sort field(ASC or DESC).
Rank: 4
Rank: 4
Rank: 4
Rank: 2
Rank: 4
Rank: 2
Rank: 10
Rank: 5
Rank: 2
Rank: 2
Rank: 3
Rank: 1
Rank: 4
Rank: 4
Rank: 3
Rank: 2
Rank: 10
Rank: 10
Rank: 10
Rank: 10
I tried for the $sphinxObj->SetSortMode(SPH_SORT_ATTR_ASC, "Rank"); but it is throwing irrelevant records. Please any suggestion on this and how do i sort values that defined in SetSelect alias field?
Right now the
Rankis not a defined attribute, so you can’t useSPH_SORT_ATTR_ASC.You want to sort based on an expressions, use
SPH_SORT_EXPRinstead.