Adds a more efficient query optimizer.

Plus refactoring, code cleanup.
PoC implementation of REST query server.
Uses $or-query, rather than chained query iterators.