https://github.com/abicky/query-matcher-js
JavaScript matcher for user queries
https://github.com/abicky/query-matcher-js
Last synced: 10 months ago
JSON representation
JavaScript matcher for user queries
- Host: GitHub
- URL: https://github.com/abicky/query-matcher-js
- Owner: abicky
- Created: 2014-01-26T04:58:05.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-01-27T23:59:20.000Z (over 12 years ago)
- Last Synced: 2025-05-14T00:38:45.289Z (about 1 year ago)
- Language: CoffeeScript
- Homepage:
- Size: 160 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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`.
```javascript
var matcher = new QuerMatcher(query);
matcher.match(string);
```
When the query contains no uppercase characters, it matches strings case insensitively.
```javascript
var matcher = new QueryMatcher('ap');;
matcher.match('apple'); // => true
matcher.match('Apple'); // => true
```
When the query contains uppercase characters, it matches strings case sensitively.
```javascript
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.
```javascript
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.
```javascript
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.
```javascript
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](http://opensource.org/licenses/MIT).