So, in the app, I do something like this:
Item.all(:order => sort).select { |item| item.to_s.downcase.include? search.to_s.downcase }
Where sort
is an array of fields to order by. By default (with lazy-loading enabled), the query output from DataMapper looks like the following (on a table of 8601 rows):
~ (0.142849) SELECT "id", "created_at", "updated_at" FROM "items" ORDER BY "artist", "title", "year", "label", "format"
~ (0.136413) SELECT "id", "title" FROM "items" ORDER BY "artist", "title", "year", "label", "format"
~ (0.126948) SELECT "id", "artist" FROM "items" ORDER BY "artist", "title", "year", "label", "format"
~ (0.125949) SELECT "id", "year" FROM "items" ORDER BY "artist", "title", "year", "label", "format"
~ (0.126458) SELECT "id", "label" FROM "items" ORDER BY "artist", "title", "year", "label", "format"
~ (0.125696) SELECT "id", "format" FROM "items" ORDER BY "artist", "title", "year", "label", "format"
~ (0.127110) SELECT "id", "condition" FROM "items" ORDER BY "artist", "title", "year", "label", "format"
~ (0.127446) SELECT "id", "color" FROM "items" ORDER BY "artist", "title", "year", "label", "format"
~ (0.126961) SELECT "id", "price_paid" FROM "items" ORDER BY "artist", "title", "year", "label", "format"
With lazy-loading disabled, the output of the same line looks like this:
~ (0.153376) SELECT "id", "created_at", "updated_at", "title", "artist", "year", "label", "format", "condition", "color", "price_paid" FROM "items" ORDER BY "artist", "title", "year", "label", "format"