Skip to content

abicky/query-matcher-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaScript matcher for user queries

This matcher supports some queries, like queries for search engines.

Download

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

Usage

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

Demo

http://abicky.github.io/query-matcher-js/

Author

Takeshi Arabiki (abicky)

Copyright and License

Copyright (c) 2014 Takeshi Arabiki licensed under the MIT license.

About

JavaScript matcher for user queries

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published