Lightweight and performant Lucene-like parser and search engine.
import {
filter,
highlight,
parse,
test,
} from 'liqe';
const persons = [
{
height: 180,
name: 'John Morton',
},
{
height: 175,
name: 'David Barker',
},
{
height: 170,
name: 'Thomas Castro',
},
];
Filter a collection:
filter(parse('height:>170'), persons);
// [
// {
// height: 180,
// name: 'John Morton',
// },
// {
// height: 175,
// name: 'David Barker',
// },
// ]
Test a single object:
test(parse('name:John'), persons[0]);
// true
test(parse('name:David'), persons[0]);
// false
Highlight matching fields and substrings:
test(highlight('name:john'), persons[0]);
// [
// {
// keyword: 'John',
// path: 'name',
// }
// ]
test(highlight('height:180'), persons[0]);
// [
// {
// path: 'height',
// }
// ]
Search for word "foo" in any field.
foo
Search for word "foo" in the title
field.
title:foo
Search for phrase "foo bar" in the title
field.
title:"foo bar"
Search for phrase "foo bar" in the title
field AND the phrase "quick fox" in the body
field.
title:"foo bar" AND body:"quick fox"
Search for either the phrase "foo bar" in the title
field AND the phrase "quick fox" in the body
field, or the word "fox" in the title
field.
(title:"foo bar" AND body:"quick fox") OR title:fox
Search for value greater or equal to 100 and lower or equal to 200 in the height
field.
height:[100 TO 200]
Search for value greater than 100 and lower than 200 in the height
field.
height:{100 TO 200}
Search for value greater than 100 in the height
field.
height:>100
Search for value greater than or equal to 100 in the height
field.
height:>=100
Search for any word that starts with "foo" in the title
field.
title:foo*
Search for any word that starts with "foo" and ends with bar in the title
field.
title:foo*bar
The following Lucene abilities are not supported:
If you are going to modify parser, then use npm run watch
to run compiler in watch mode.
Before making any changes, capture the current benchmark on your machine using npm run benchmark
. Run benchmark again after making any changes. Before committing changes, ensure that performance is not negatively impacted.