Search in sources :

Example 1 with InvalidQueryException

use of org.apache.atlas.catalog.exception.InvalidQueryException in project incubator-atlas by apache.

the class QueryFactory method create.

private QueryExpression create(Request request, ResourceDefinition resourceDefinition) throws InvalidQueryException {
    String queryString;
    if (request.getCardinality() == Request.Cardinality.INSTANCE) {
        String idPropertyName = resourceDefinition.getIdPropertyName();
        queryString = String.format("%s:%s", idPropertyName, request.<String>getProperty(idPropertyName));
    } else {
        queryString = request.getQueryString();
    }
    QueryExpression queryExpression;
    if (queryString != null && !queryString.isEmpty()) {
        QueryParser queryParser = new QueryParser(Version.LUCENE_48, "name", new KeywordAnalyzer());
        queryParser.setLowercaseExpandedTerms(false);
        queryParser.setAllowLeadingWildcard(true);
        Query query;
        try {
            query = queryParser.parse((String) escape(queryString));
        } catch (ParseException e) {
            throw new InvalidQueryException(e.getMessage());
        }
        LOG.info("LuceneQuery: {}", query);
        queryExpression = create(query, resourceDefinition);
    } else {
        queryExpression = new AlwaysQueryExpression();
    }
    // add query properties to request so that they are returned
    request.addAdditionalSelectProperties(queryExpression.getProperties());
    return queryExpression;
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) RegexQuery(org.apache.lucene.sandbox.queries.regex.RegexQuery) ParseException(org.apache.lucene.queryparser.classic.ParseException) InvalidQueryException(org.apache.atlas.catalog.exception.InvalidQueryException)

Aggregations

InvalidQueryException (org.apache.atlas.catalog.exception.InvalidQueryException)1 KeywordAnalyzer (org.apache.lucene.analysis.core.KeywordAnalyzer)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 QueryParser (org.apache.lucene.queryparser.classic.QueryParser)1 RegexQuery (org.apache.lucene.sandbox.queries.regex.RegexQuery)1