text-query
Simple query tokenizer for turning a query string into a comparator for other text fields.
Usage
var Query = ; // Create a query: spaces are OR'd groups and commas AND groups, with// double quoted strings being one search entity.var q = "'death metal', swedish finnish, guitar bass drums"; // This query only returns true of "death metal" is in the text,// along with "swedish" OR "finnish", and an instrument ("guitar" or "bass" or "drums")// must also be in the string.q; // trueq; // trueq; // false, 'death metal' is not a single stringq; // false, missing 'swedish' or 'finnish' // Can also handle arrays of strings for matchingq; // true
Installation
$ npm install text-query
API
new Query(query)
Creates a new Query object with query
string.
query.matches(text)
Returns a boolean indicating whether or not text
matches the internal query
. text
can also be an array of strings.
Testing
npm test
License
MIT License, Copyright (c) 2014 Jordan Santell