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; }
public AtlasQuery createEntityTagQuery(Request request) throws InvalidQueryException { ResourceDefinition entityTagDefinition = new EntityTagResourceDefinition(); QueryExpression queryExpression = create(request, entityTagDefinition); String guid = request.getProperty("id"); return new AtlasEntityTagQuery(queryExpression, entityTagDefinition, guid, request); }
public AtlasQuery createTermQuery(Request request) throws InvalidQueryException { ResourceDefinition termDefinition = new TermResourceDefinition(); QueryExpression queryExpression = create(request, termDefinition); TermPath termPath = request.getProperty("termPath"); return new AtlasTermQuery(queryExpression, termDefinition, termPath, request); }