This matcher supports some queries, like queries for search engines.
You can download the JavaScript file from the following link:
http://abicky.github.io/query-matcher-js/lib/query-matcher.js
You can also build the file by the following steps:
$ git clone https://github.com/abicky/query-matcher-js.git
$ cd ./query-matcher-js/
$ npm install
$ npm run build
First, initialize QuerMatcher
with the query, then call QuerMatcher#match
with the string.
QuerMatcher#match
returns true
if the query matches the string, otherwise returns false
.
var matcher = new QuerMatcher(query);
matcher.match(string);
When the query contains no uppercase characters, it matches strings case insensitively.
var matcher = new QueryMatcher('ap');;
matcher.match('apple'); // => true
matcher.match('Apple'); // => true
When the query contains uppercase characters, it matches strings case sensitively.
var matcher = new QueryMatcher('Ap');
matcher.match('apple'); // => false
matcher.match('Apple'); // => true
When the query contains multiple words, it matches strings which contain the both words.
var matcher = new QueryMatcher('ap le');
matcher.match('apple'); // => true
matcher.match('grape'); // => false
When the query contains 'OR' keyword, it matches strings which contain the each word.
var matcher = new QueryMatcher('ap OR le');
matcher.match('grape'); // => true
matcher.match('lemon'); // => true
matcher.match('orange'); // => false
When the query contains words with '-' prefix, it matches strings which don't contain the word.
var matcher = new QueryMatcher('-ap');
matcher.match('apple'); // => false
matcher.match('orange'); // => true
http://abicky.github.io/query-matcher-js/
Takeshi Arabiki (abicky)
Copyright (c) 2014 Takeshi Arabiki licensed under the MIT license.