Filterable
Filterable is a Node.JS module to parse GitHub-like search queries, for example: cats stars:>10
. It can generates MongoDB or Elasticsearch queries.
This module is perfect to integrates complex search (like GitHub) into your application. It integrates perfectly with MongoDB but can also easily be adapted to other databases.
Queries
Type | Example |
---|---|
Query for tags | cat |
Query for multiple tags | cat dog , "Hello World" |
Exclude results containing a certain word | cat NOT dog |
Query for equality | username:Samypesse , name:"Samy Pesse" |
Query for values greater than another value | stars:>10 , stars:>=10 |
Query for values less than another value | stars:<100 , stars:<=100 |
Mix query for tags and condition | cat stars:>10 stars:<100 |
Filter qualifiers based on exclusion | cats stars:>10 NOT language:javascript |
How to use it?
Install it using:
$ npm install filterable
Parse a query string:
var filterable = ; var query = filterable ;
Output query for a database:
var mongQuery = query;
Filter and customize queries using QueryBuilder
:
var builder = filterable; // Define mapping, by default all fields are accepted and piped as stringbuilder; // Reject a fieldbuilder; // Parse queries (return a Query object)var q1 = buildervar q2 = builder;