tags:

views:

265

answers:

2

Hi,

I know you can sort by integer values in sphinx but is there a way I can get sphinx to sort by a text field alphabetically?

I want to search on first name and instead of sorting on relevance, I'd like to sort by the first name alphabetically. I know I can do this in mysql but in mysql I don't have features like stemming (as far as I know).

Thanks Everyone!

+1  A: 

As far as I know you can't sort by anything other than attributes (and a few special attributes like @weight, etc.). Currently attributes cannot be strings, but this feature should be coming in 0.9.10 from what he's said about it.

http://www.sphinxsearch.com/docs/current.html#sorting-modes

Ty W
+2  A: 

You can use strings as ordinal attributes - Sphinx will collect all values of the given column, sort them alphabetically, then give the first one a value of 1, the second a value of 2, and so forth. This allows for sorting, but not filtering.

pat
very nice... forgot about that one in the docs.
Ty W
Fantastic. I'll give that a go.
Mark L
I noticed that this isn't case insensitive. E.g. AOL will come before America.
dd
That's correct. You'll either want to create a cached column which stores all-downcase or all-uppercase versions of the original column, and then add that as an attribute; Or: use a MySQL/Postrgres function to transform the column on the fly in a SQL snippet for the attribute instead. Look at the end of the Fields section in the docs for a rather apt example. http://freelancing-god.github.com/ts/en/indexing.html
pat

related questions