ingenuitas/SimpleSeer — pull request #118 by rick446 (2012-06-07 21:30:21+00:00)
Title: Rc/111: URL for searching frames

There is a (manual) test in 'tester.py'. Difficult to write a unit test because the view relies on the new agg framework, which is not yet implemented in MIM.

Some things to be aware of:

- You *must* upgrade to MongoDB 2.1 to use this. I have updated default.cfg to point to port 27018 because this is where I am running this version of MongoDB (the 'standard' 27017 is still running 2.0)
- I have embedded results inside the frame objects. The existing Result objects *should* still be there, and get updated as before whenever the Frame is saved.
- The url path is /frames, and it takes 4 arguments:
- **filters** - MongoDB-style query (json) for filtering the documents
- **sorts** - MongoDB-style sorting [ ('field1', 1), ('field2', -1) ] sorts by field1 ascending, field2 descending
- **skip** - standard: skip this many matching documents before starting to return new ones
- **limit** - limit the response to this many documents

The implementation first applies the **filters** param to the collection as a whole, which winnows down which data we want to look at. This does *not* actually give us the frames we're interested in (in some cases), but it *does* give us a superset. We then unwind both results and features out of the frame, basically giving us two LEFT JOINS. Then the filters are reapplied (anything that references a feature or a result will now be applied to each feature/result one by one). The docs are then sorted and the _id field is stripped off.

Once we have the _ids, we need to uniquify them and apply the skip and limit. Once this is done, we query MongoDB again for the identified frames and return them in the same order as our $sort generated them.