Re-implementation of sort by relevance

Sorting search results by relevance was originally implemented using 2-3 queries to the database, which was costly in terms of performance.  The code has been refactored to use only 1 database query, and separation and sorting of results has been re-implemented in the application layer for improved response time.