use of org.codice.alliance.nsili.common.grammar.BqsParser in project alliance by codice.
the class BqsConverter method convertBQSToDDF.
public Filter convertBQSToDDF(String query) {
query = query.trim();
LOGGER.debug("Original Query: {}", query);
ANTLRInputStream inputStream = new ANTLRInputStream(query);
// transforms characters into tokens
BqsLexer lex = new BqsLexer(inputStream);
// a token stream
CommonTokenStream tokens = new CommonTokenStream(lex);
// transforms tokens into parse trees
BqsParser parser = new BqsParser(tokens);
BqsTreeWalkerListener bqsListener = new BqsTreeWalkerListener(filterBuilder);
ParseTree tree = parser.query();
ParseTreeWalker.DEFAULT.walk(bqsListener, tree);
Filter filter = bqsListener.getFilter();
if (filter != null && StringUtils.isNotBlank(filter.toString())) {
LOGGER.debug("Parsed Query: {}", filter);
} else {
filter = filterBuilder.attribute(Metacard.ANY_TEXT).is().text("*");
LOGGER.debug("After parsing filter, didn't have any query parameters. Defaulting to everything search: {}", filter);
}
return filter;
}
Aggregations