Implemented more complex seach capabilities using Mango (MongoDB like) query syntax #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #16 asks for more complex queries.
The solution
Using the solution in this PR, complex queries is written as a PouchDB selector, which is the same as CouchDB selector, which is a Mango query language, which is inspired by MongoDB query language.
Query parsing and rows matching are performed by using pouchdb-selector-core. All comparison operators ($eq, $ne, $gt, $lt, etc.) and logical operators ($and, $or, etc.) have been implemented by pouchdb-selector-core.
The reasonings
Reasonings of using MongoDB query language and pouchdb-selector-core:
?search={column1:value1,column2:value2}still works, and it is the same as?search={column1:{$eq:value1},column2:{$eq:value2}}. It means it retains backward compatibility.The implementation
I don't use existing match function in pouchdb-selector-core, which is
matchesSelector, because it only perform match for one row. I think it is not efficient to process the query every row. The query doesn't change so it is better to only process the query once and then use it to filter the dataset. This is why I usemassageSelectorandfilterInMemoryFieldsin the implementation because these two functions is performedmatchesSelector.