lucene-filter.js

Data filter for lucene queries
git clone git://git.finwo.net/lib/lucene-filter.js
Log | Files | Refs | README | LICENSE

commit 412d5bfbb768dbee2d2e1ce356c69958423d2a15
parent c5e39c6a01f604eae74066688c99104386d262bd
Author: finwo <finwo@pm.me>
Date:   Wed, 28 Nov 2018 10:11:26 +0100

Found what the issue was

Diffstat:
Aexample.js | 22++++++++++++++++++++++
Msrc/filters/string/contains.js | 2+-
2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/example.js b/example.js @@ -0,0 +1,22 @@ +const lucene = require('./src/index'); +let result; + +const data = [ + { name: 'C-3PO' , description: 'Protocol droid.' , species: 'Droid' }, + { name: 'R2-D2' , description: 'Astromech droid built on Naboo.', species: 'Droid' }, + { name: 'Anakin Skywalker', description: 'Fallen Jedi, the chosen one.' , species: 'Human' }, + { name: 'Obi-Wan Kenobi' , description: 'Jedi Master.' , species: 'Human' }, + { name: 'Moon Moon' , description: 'Mentally challenged wolf.' , species: 'Wolf' }, +]; + +// Prints an array with both R2-D2 and C-3PO +console.log(data.filter(lucene('species: droid'))); + +// Prints an array with only R2-D2 +console.log(data.filter(lucene('astromech'))); + +// Prints an array with both jedi +console.log(data.filter(lucene('jedi'))); + +// Prints an array with only the outcast +console.log(data.filter(lucene('name: "moon moon"'))); diff --git a/src/filters/string/contains.js b/src/filters/string/contains.js @@ -5,7 +5,7 @@ module.exports = { if (!query) return false; if ('object' !== typeof query) return false; if ('string' !== typeof query.field) return false; - return 'string' !== typeof query.term; + return 'string' === typeof query.term; }, compile: function (query) { return function (data) {