Cleanups: Cleaner way to set dictionaries
Minor globals cleanup

Make clear how many globals there are, and make them to appear at the
top of the code block.
Cleanups: Just shorten code
Cleanup: More readable way to generate the results HTML page
Cleanup: Search object should know how to display its search terms

Also the use of properties allows us to have a cleaner code.
Cleanup: Search object should know if it has a valid search term
SQL cleanup

Use uppercase, span several lines to improve readability, use
implicit line continuation, invert quoting to avoid escaping.
Cleanup: Invert quoting to avoid escaping
Cleanups: Indents, whitespace and long lines wrap
Cleanup: Remove unnecessary function
Embedded HTML cleanups to improve readability

* Move template context retrieval to the top of the code block,
* Use format() to avoid mixing string with variables,
* Use implicit line continuation instead of endlessly concatenating strings,
* Use print as a function.

This a previous step to strip out the HTML into proper external templates.