George Armhold
George Armhold

Reputation: 31064

Sunspot: can't use "order_by" on text fields?

If I try to use order_by on a text field I get: "no field configured with name title".

Works fine on fields of type "string". So I end up using a workaround like:

searchable do 
  text :title

  string :title_sortable do 
    title
  end
end

Is there any reason why we cannot order_by on text fields?

Upvotes: 2

Views: 867

Answers (1)

user1452132
user1452132

Reputation: 1768

This is by Solr design. Text fields are tokenized. Sorting on a tokenized field does not make sense.

Consider the following two white space tokenized fields in two different docs.

"quick fire ammo" "black bear"

When you sort them in ascending order, the first one should not appear before the second, just because it has the word "ammo" in it.

That is why, the sortable fields should be defined as String.

Upvotes: 3

Related Questions