Search in sources :

Example 1 with RecoveringParseRunner

use of org.parboiled.parserunners.RecoveringParseRunner in project ddf by codice.

the class OpenSearchQuery method addContextualFilter.

public void addContextualFilter(String searchTerm, String selectors) throws ParsingException {
    String methodName = "addContextualFilter";
    Filter filter = null;
    KeywordFilterGenerator keywordFilterGenerator = new KeywordFilterGenerator(filterBuilder);
    KeywordTextParser parser = Parboiled.createParser(KeywordTextParser.class);
    // translate the search terms into an abstract syntax tree
    ParsingResult<ASTNode> result = new RecoveringParseRunner(parser.inputPhrase()).run(searchTerm);
    // make sure it's a good result before using it
    if (result.matched && !result.hasErrors()) {
        filter = generateContextualFilter(selectors, keywordFilterGenerator, result);
    } else if (result.hasErrors()) {
        throw new ParsingException("Unable to parse keyword search phrase. " + generateParsingError(result));
    }
    if (filter != null) {
        filters.add(filter);
    }
}
Also used : KeywordFilterGenerator(org.codice.ddf.endpoints.KeywordFilterGenerator) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) BBoxSpatialFilter(org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter) ParsingException(org.parboiled.errors.ParsingException) ASTNode(org.codice.ddf.endpoints.ASTNode) RecoveringParseRunner(org.parboiled.parserunners.RecoveringParseRunner) KeywordTextParser(org.codice.ddf.endpoints.KeywordTextParser)

Example 2 with RecoveringParseRunner

use of org.parboiled.parserunners.RecoveringParseRunner in project ddf by codice.

the class OpenSearchQuery method addContextualFilter.

public void addContextualFilter(String searchTerms, String selectors) throws ParsingException {
    Filter filter = null;
    KeywordFilterGenerator keywordFilterGenerator = new KeywordFilterGenerator(filterBuilder);
    KeywordTextParser parser = Parboiled.createParser(KeywordTextParser.class);
    // translate the search terms into an abstract syntax tree
    ParsingResult<ASTNode> result = new RecoveringParseRunner(parser.inputPhrase()).run(searchTerms);
    // make sure it's a good result before using it
    if (result.matched && !result.hasErrors()) {
        filter = generateContextualFilter(selectors, keywordFilterGenerator, result);
    } else if (result.hasErrors()) {
        throw new ParsingException("Unable to parse keyword search phrase. " + generateParsingError(result));
    }
    if (filter != null) {
        filters.add(filter);
    }
}
Also used : KeywordFilterGenerator(org.codice.ddf.opensearch.endpoint.KeywordFilterGenerator) PolygonSpatialFilter(org.codice.ddf.opensearch.endpoint.query.filter.PolygonSpatialFilter) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) Filter(org.opengis.filter.Filter) BBoxSpatialFilter(org.codice.ddf.opensearch.endpoint.query.filter.BBoxSpatialFilter) ParsingException(org.parboiled.errors.ParsingException) ASTNode(org.codice.ddf.opensearch.endpoint.ASTNode) RecoveringParseRunner(org.parboiled.parserunners.RecoveringParseRunner) KeywordTextParser(org.codice.ddf.opensearch.endpoint.KeywordTextParser)

Aggregations

SpatialDistanceFilter (ddf.catalog.impl.filter.SpatialDistanceFilter)2 SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)2 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)2 Filter (org.opengis.filter.Filter)2 ParsingException (org.parboiled.errors.ParsingException)2 RecoveringParseRunner (org.parboiled.parserunners.RecoveringParseRunner)2 ASTNode (org.codice.ddf.endpoints.ASTNode)1 KeywordFilterGenerator (org.codice.ddf.endpoints.KeywordFilterGenerator)1 KeywordTextParser (org.codice.ddf.endpoints.KeywordTextParser)1 ASTNode (org.codice.ddf.opensearch.endpoint.ASTNode)1 KeywordFilterGenerator (org.codice.ddf.opensearch.endpoint.KeywordFilterGenerator)1 KeywordTextParser (org.codice.ddf.opensearch.endpoint.KeywordTextParser)1 BBoxSpatialFilter (org.codice.ddf.opensearch.endpoint.query.filter.BBoxSpatialFilter)1 PolygonSpatialFilter (org.codice.ddf.opensearch.endpoint.query.filter.PolygonSpatialFilter)1 BBoxSpatialFilter (org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter)1 PolygonSpatialFilter (org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter)1