Search in sources :

Example 1 with BqsParser

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;
}
Also used : BqsLexer(org.codice.alliance.nsili.common.grammar.BqsLexer) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) BqsParser(org.codice.alliance.nsili.common.grammar.BqsParser) Filter(org.opengis.filter.Filter) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1 BqsLexer (org.codice.alliance.nsili.common.grammar.BqsLexer)1 BqsParser (org.codice.alliance.nsili.common.grammar.BqsParser)1 Filter (org.opengis.filter.Filter)1