brandonblack/mongo-tools — pull request #32 by macworld (2013-02-11 17:15:00+00:00)
Title: Add indexes suggestions function

**Changes**
-
- EvaluationResult` is now the parent class of `EfficencyResult` and `IndexResult`
- Complete `chek_for_indexes` method
- Add some test cases

**Implementation of index suggestion**
-
I followed [Optimizing MongoDB Compound Indexes] (http://java.dzone.com/articles/optimizing-mongodb-compound?mz=36885-nosql) to generate indexes suggestions.

Indexes fields will be generated in this order:
- EQUAL_TYPE `e.g. "A": "10"`
- SORT_TYPE `e.g. "orderby" => { "C": 1.0 }`
- RANGE_TYPE `e.g. "A": {"$gt": 13, "$lt": 27}`

Analyzer will ignore the field which includes currently unsupported operators such as `$regex`, `$where` and `$near`

Analyzer will set the result an`Optional` flag when encounter unsupported operators in query because may cause index suggestions inaccurate.

**Known problem**
-
Analyzer cannot handle query `"field': { 'sub1': 1, 'sub2': 2 }` properly.
I haven't found a good way to handle it when queries become more complex, like
`"field': { 'sub1': {'sub3': 3, 'sub': 4}, 'sub2': 2 }`
Actually I don't think these queries are meaningful. Is it necessary to handle it?