Memory filter implementation/improvements

Implement filters compatible with CouchDB for the Memory engine.

Based loosely on the old memory-filters branch, plus reading through the CouchDB view.js file to ensure compatibility.

Includes test cases.