I use NHibernate to search by item name. I get a paged list of items from the database, and I order it by name in ascending order.
So, if I search for a βtermβ, I return a results page that contains a βtermβ anywhere in the result, and the page is sorted alphabetically.
For example, the results might look like this:
a term d term g term j term p term s term term 1 term 2 v term z term
Technically, this list is correct because it is sorted alphabetically.
However, technically correct is not enough for the client. They want the list to be ordered first by relevance of the searched word, and then in alphabetical order.
Thus, the result will be
term 1 term 2 a term d term g term j term p term s term v term z term
I do not know how to build this query, or if it is possible. If this could be done in the application, it would be much simpler, but because of the paging, this should be done in the database. This is what complicates the situation. Can someone please point me in the right direction?
source share