I want to group-by one attribute, then sort those groups using the min- or max-value of a different attribute, in either ascending or descending order.
We've defined a source with a bunch of attributes including:
sql_attr_uint = CategoryId
sql_attr_str2ordinal = SortableName
Without grouping, we can sort results using SortableName (e.g. sort by product-name in ascending or descending order) using e.g. $sphinx->SetSortMode(SPH_SORT_ATTR_DESC, 'SortableName')
When we try grouping by CategoryId, we want to select the product with the 'lowest' name, then sort the groups by that value. We tried this with no success:
$sphinx->SetGroupBy('CategoryId', SPH_GROUPBY_ATTR, 'MIN(SortableName) asc');
After a little misinterpretation of the docs we ended up trying:
$sphinx->SetSelect('MIN(SortableName) AS FirstName');
$sphinx->SetGroupBy('CategoryId', SPH_GROUPBY_ATTR, 'FirstName asc');
This doesn't work either.
It's notable that we're trying to do this using a sql_attr_str2ordinal field - which we want to treat simply as a number. When we tried this using a C# API, we got a sphinx error stating "attribute sortablename is of unsupported type (type=3)"
Any idea how to sort groups this way?