Introduce QueryResult class.

This simplifies various bits.

Related change in this commit: instead of passing query_id as a
GET parameter to distinguish saved queries, just use the query
xpath and check if it exists in the database. This simplifies the
logic in app.py, plus it'll make caching work even the query is
typed in the search box instead of selected from the list.