import { filter } from 'search-expression-parser';
// ...
function filterMyData(parsedSearchExpression) {
const myData = [1, 2, 3, 4];
const filteredData = filter(myData, parsedSearchExpression, dataMatcher);
console.log(filteredData);
}
function dataMatcher(expressionNode, item) {
/*
Depending on the data in the node, we can perform filtering.
In this example, we want to allow queries that look like this:
num:1 OR num:2 OR NOT num:5
The DataMatcher function may get called on two types of nodes:
- Key-Value nodes like “name:bob”
- Value-Only nodes like “bob”
In this example, we want to treat Value-Only nodes as invalid (i.e. as a syntax error).
Also, we want to treat keys of a Key-Value node as a syntax error
if the key is not “num”.
*/