Allow sorting of the database query only for a single column.

This is a low cost on flexibility to pay for a much simpler code.
This commit also changes the model api for the query view collection.
Change the way the sorting of the result of the query is done.

Only sort as long as we need to, stop when we reach desired number of rows.