More efficiently sort small result sets

We define small as fewer than five hundred results. Arbitrarily,
I've not tested for optimality of size.

The main part of this is to insert a WHERE clause into the SQL
generated when sorting for small result sets. Then we can avoid
the NSSet lookups when looping through the result set, and rely on
the result set already being filtered to the correct result set.

This speeds things up in two ways:

- Avoid extra loops for ordered doc IDs not in result set.
- Avoid lookups inside the NSSet of results.

Fixes #7
Add invalid syntax tests for query

Add Invalid syntax tests for the following operators:
- $or
- $eq

Added tests for $lt and $gt operators on strings
Add array comparison syntax tests

Abort query when syntax is invalid, based on what
is accepted in the service.

Notes:

{$or:[{"name":"mike}]} looks invalid however cloudant query in the service
accepts this as a valid query, so this implementation for sync also accepts
this as a valid query.

Add $lt and $gt tests

Add an array compare test

Add $eq tests

Add $eq tests and logic to abort query when test syntax is invalid

Update tests for $eq operator to use correctish syntax where  appropriate

Closes issue #24
Merge pull request #26 from cloudant/7-sort-small-resultsets

More efficiently sort small result sets
Merge pull request #13 from cloudant/invalid_syntax_tests

Invalid syntax tests
Add support for  operator
Add invalid syntax test

Added invalid syntac test
Fix crash if $exists argument is not a boolean via NSNumber