lucene-querystring
v1.0.3
Published
Convert a mongo query like object to lucene query string
Downloads
417
Maintainers
Readme
lucenequery
Convert a mongo query like object to lucene query string
Install
npm i lucene-querystring
Example
var lucene-querystring = require('lucene-querystring');
lucene-querystring.build({
name: 'leo'
});
> name:leo
Baisc Query
fiter with default
and
operatorvar test = { name: 'leo', status: 'A' }; var q = luceneQueryString.build(test); assert.equal(q, 'name:leo AND status:A');
in
query item in a arrayvar test = { id: [1,2,3] }; var q = luceneQueryString.build(test); assert.equal(q, 'id:(1 OR 2 OR 3)');
'range' query like from end
var test = { id: { $gt: 100, $lt: 1000 } }; var q = luceneQueryString.build(test); assert.equal(q, 'id:[ 100 TO 1000 ]');
or
queryvar test = { $or: [{ id: 100 },{ id: 10 }] }; var q = luceneQueryString.build(test); assert.equal(q, 'id:100 OR id:10');
null
ornot null
var test = { name: { "$null": false }, }; var q = luceneQueryString.build(test); assert.equal(q, 'name:[* TO *]');
Complex query
complex
or
queryvar test = { $or: [{ $and:[{ id:1 },{ num:1 }] },{ $and:[{ id:2 },{ num:2 }] }] }; var q = luceneQueryString.build(test); assert.equal(q, '(id:1 AND num:1) OR (id:2 AND num:2)');
complex
and
queryvar test = { $and: [{ $or: [{ id:1 },{ id:2 }] },{ $or: [{ num:1 },{ num:2 }] }] }; var q = luceneQueryString.build(test); assert.equal(q, '(id:1 OR id:2) AND (num:1 OR num:2)');
Others
for other query please checkout and find in the test case.
Test
npm test
will run all test case in test
folder