Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jsantell/text-query
Generate simple boolean text queries
https://github.com/jsantell/text-query
Last synced: about 1 month ago
JSON representation
Generate simple boolean text queries
- Host: GitHub
- URL: https://github.com/jsantell/text-query
- Owner: jsantell
- License: mit
- Created: 2014-12-21T20:24:50.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-12-21T21:47:56.000Z (about 10 years ago)
- Last Synced: 2024-11-20T00:23:00.405Z (about 2 months ago)
- Language: JavaScript
- Size: 117 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# text-query
[![Build Status](http://img.shields.io/travis/jsantell/text-query.svg?style=flat-square)](https://travis-ci.org/jsantell/text-query)
[![Build Status](http://img.shields.io/npm/v/text-query.svg?style=flat-square)](https://www.npmjs.org/package/text-query)Simple query tokenizer for turning a query string into a comparator for other text fields.
## Usage
```js
var Query = require("text-query");// Create a query: spaces are OR'd groups and commas AND groups, with
// double quoted strings being one search entity.
var q = new Query("'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.matches("swedish death metal for guitarists"); // true
q.matches("death metal for finnish bassists"); // true
q.matches("death to swedish metal drums"); // false, 'death metal' is not a single string
q.matches("norwegian death metal for guitarists"); // false, missing 'swedish' or 'finnish'// Can also handle arrays of strings for matching
q.matches(["death metal", "swedish", "guitar"]); // 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