Refactor search query handling

Move certain parts to a single function to not repeat everything in all
smart_search_ functions.

Removed the kludge around UTF8 handling - since we now depend on Python
2.7.3 it shouldn't be a problem.