function advancedSearch(data, argQuery, fields) {
let query = argQuery;
if (
query.toLowerCase().indexOf(" or ") == -1 &&
query.toLowerCase().indexOf(" -") == -1 &&
query.toLowerCase().indexOf(" and ") == -1 &&
query.toLowerCase().indexOf('"') == -1
) {
query = argQuery.replaceAll(" ", " OR ");
}
const tokens = tokenizeQuery(query);
const queryTree = parseTokens(tokens);
const implicitOrTokens = tokens
.filter(
(token) => token.toUpperCase() !== "AND" && token.toUpperCase() !== "OR"
)
.map((token) => [token]);
mutable debug.push({
tokens,
query,
argQuery,
implicitOrTokens,
concatted: queryTree.concat([implicitOrTokens]),
queryTree
});
return data.filter((obj) =>
matchesQuery(obj, queryTree.length ? queryTree : implicitOrTokens, fields)
);
}