in oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticRequestHandler.java [676:772]
private List<Query> nonFullTextConstraints(IndexPlan plan, PlanResult planResult) {
final BiPredicate<Iterable<String>, String> any = (iterable, value) -> StreamSupport
.stream(iterable.spliterator(), false).anyMatch(value::equals);
final List<Query> queries = new ArrayList<>();
Filter filter = plan.getFilter();
if (!filter.matchesAllTypes()) {
Optional<Query> nodeTypeConstraints = nodeTypeConstraints(planResult.indexingRule, filter, elasticIndexDefinition);
nodeTypeConstraints.ifPresent(queries::add);
}
String path = FulltextIndex.getPathRestriction(plan);
switch (filter.getPathRestriction()) {
case ALL_CHILDREN:
if (!"/".equals(path)) {
queries.add(newAncestorQuery(path));
}
break;
case DIRECT_CHILDREN:
queries.add(Query.of(q -> q.bool(b -> b.must(newAncestorQuery(path)).must(newDepthQuery(path, planResult)))));
break;
case EXACT:
// For transformed paths, we can only add path restriction if absolute path to property can be deduced
if (planResult.isPathTransformed()) {
String parentPathSegment = planResult.getParentPathSegment();
if (!any.test(PathUtils.elements(parentPathSegment), "*")) {
queries.add(newPathQuery(path + parentPathSegment));
}
} else {
queries.add(newPathQuery(path));
}
break;
case PARENT:
if (PathUtils.denotesRoot(path)) {
// there's no parent of the root node
// we add a path that can not possibly occur because there
// is no way to say "match no documents" in Lucene
queries.add(newPathQuery("///"));
} else {
// For transformed paths, we can only add path restriction if absolute path to property can be deduced
if (planResult.isPathTransformed()) {
String parentPathSegment = planResult.getParentPathSegment();
if (!any.test(PathUtils.elements(parentPathSegment), "*")) {
queries.add(newPathQuery(PathUtils.getParentPath(path) + parentPathSegment));
}
} else {
queries.add(newPathQuery(PathUtils.getParentPath(path)));
}
}
break;
case NO_RESTRICTION:
break;
}
for (Filter.PropertyRestriction pr : filter.getPropertyRestrictions()) {
String name = pr.propertyName;
if (QueryConstants.REP_EXCERPT.equals(name) || QueryConstants.OAK_SCORE_EXPLANATION.equals(name)
|| QueryConstants.REP_FACET.equals(name)) {
continue;
}
if (QueryConstants.RESTRICTION_LOCAL_NAME.equals(name)) {
if (planResult.evaluateNodeNameRestriction()) {
queries.add(nodeName(pr));
}
continue;
}
if (IndexConstants.INDEX_TAG_OPTION.equals(name) || IndexConstants.INDEX_NAME_OPTION.equals(name)) {
continue;
}
if (pr.first != null && pr.first.equals(pr.last) && pr.firstIncluding && pr.lastIncluding) {
String first = pr.first.getValue(Type.STRING);
first = first.replace("\\", "");
if (JCR_PATH.equals(name)) {
queries.add(newPathQuery(first));
continue;
} else if ("*".equals(name)) {
// TODO Revisit reference constraint. For performant impl
// references need to be indexed in a different manner
queries.add(referenceConstraint(first));
continue;
}
}
PropertyDefinition pd = planResult.getPropDefn(pr);
if (pd == null) {
continue;
}
queries.add(createQuery(planResult.getPropertyName(pr), pr, pd));
}
return queries;
}