Adds header element to explain search results on search template page.
Removes old cruft, further generalizes database functions. Adds several test cases for building db queries.