use of com.b2international.index.query.Expressions.ExpressionBuilder in project snow-owl by b2ihealthcare.
the class BaseResourceSearchRequest method prepareQuery.
@Override
protected final Expression prepareQuery(RepositoryContext context) {
final ExpressionBuilder queryBuilder = Expressions.builder();
addSecurityFilter(context, queryBuilder);
addFilter(queryBuilder, OptionKey.BUNDLE_ID, String.class, ResourceDocument.Expressions::bundleIds);
if (containsKey(OptionKey.BUNDLE_ANCESTOR_ID)) {
final Collection<String> ancestorIds = getCollection(OptionKey.BUNDLE_ANCESTOR_ID, String.class);
queryBuilder.filter(Expressions.builder().should(ResourceDocument.Expressions.bundleIds(ancestorIds)).should(ResourceDocument.Expressions.bundleAncestorIds(ancestorIds)).build());
}
addFilter(queryBuilder, OptionKey.OID, String.class, ResourceDocument.Expressions::oids);
addFilter(queryBuilder, OptionKey.STATUS, String.class, ResourceDocument.Expressions::statuses);
addIdFilter(queryBuilder, ResourceDocument.Expressions::ids);
addTitleFilter(queryBuilder);
addTitleExactFilter(queryBuilder);
addUrlFilter(queryBuilder);
prepareAdditionalFilters(context, queryBuilder);
return queryBuilder.build();
}
use of com.b2international.index.query.Expressions.ExpressionBuilder in project snow-owl by b2ihealthcare.
the class SnomedEclEvaluationRequest method eval.
protected Promise<Expression> eval(BranchContext context, final DialectIdFilter dialectIdFilter) {
final Multimap<String, String> languageRefSetsByAcceptability = HashMultimap.create();
final ExpressionBuilder dialectQuery = Expressions.builder();
for (Dialect dialect : dialectIdFilter.getDialects()) {
final ExpressionConstraint languageRefSetId = dialect.getLanguageRefSetId();
final Set<String> evaluatedIds = EclExpression.of(languageRefSetId, expressionForm).resolve(context).getSync();
final Set<String> acceptabilitiesToMatch = getAcceptabilityFields(dialect.getAcceptability());
// empty set means that acceptability values are not valid and it should not match any descriptions/concepts
if (acceptabilitiesToMatch.isEmpty()) {
return Promise.immediate(Expressions.matchNone());
}
for (String acceptability : acceptabilitiesToMatch) {
languageRefSetsByAcceptability.putAll(acceptability, evaluatedIds);
}
}
languageRefSetsByAcceptability.asMap().forEach((key, values) -> {
Operator op = Operator.fromString(dialectIdFilter.getOp());
switch(op) {
case EQUALS:
dialectQuery.should(Expressions.matchAny(key, values));
break;
case NOT_EQUALS:
dialectQuery.mustNot(Expressions.matchAny(key, values));
break;
default:
throw new NotImplementedException("Unsupported dialectIdFilter operator '%s'", dialectIdFilter.getOp());
}
});
return Promise.immediate(dialectQuery.build());
}
use of com.b2international.index.query.Expressions.ExpressionBuilder in project snow-owl by b2ihealthcare.
the class SnomedEclRefinementEvaluator method evalAxiomStatements.
static Set<Property> evalAxiomStatements(final BranchContext context, final boolean groupedRelationshipsOnly, final Collection<String> sourceIds, final Collection<String> typeIds, final Collection<String> destinationIds) {
try {
// search existing axioms (no values!) defined for the given set of conceptIds
ExpressionBuilder axiomFilter = Expressions.builder().filter(hasDestinationId());
if (typeIds != null) {
axiomFilter.filter(typeIds(typeIds));
}
if (destinationIds != null) {
axiomFilter.filter(destinationIds(destinationIds));
}
if (groupedRelationshipsOnly) {
axiomFilter.filter(relationshipGroup(1, Integer.MAX_VALUE));
}
ExpressionBuilder activeOwlAxiomMemberQuery = Expressions.builder().filter(active()).filter(Expressions.nestedMatch(SnomedRefSetMemberIndexEntry.Fields.CLASS_AXIOM_RELATIONSHIP, axiomFilter.build()));
if (sourceIds != null) {
activeOwlAxiomMemberQuery.filter(SnomedRefSetMemberIndexEntry.Expressions.referencedComponentIds(sourceIds));
}
final Query<SnomedRefSetMemberIndexEntry> activeAxiomStatementsQuery = Query.select(SnomedRefSetMemberIndexEntry.class).where(activeOwlAxiomMemberQuery.build()).limit(Integer.MAX_VALUE).build();
return context.service(RevisionSearcher.class).search(activeAxiomStatementsQuery).stream().filter(owlMember -> !CompareUtils.isEmpty(owlMember.getClassAxiomRelationships())).flatMap(owlMember -> {
return owlMember.getClassAxiomRelationships().stream().filter(classAxiom -> {
return (typeIds == null || typeIds.contains(classAxiom.getTypeId())) && (destinationIds == null || destinationIds.contains(classAxiom.getDestinationId())) && (!groupedRelationshipsOnly || classAxiom.getRelationshipGroup() >= 1);
}).map(classAxiom -> {
return new Property(owlMember.getReferencedComponentId(), classAxiom.getTypeId(), classAxiom.getDestinationId(), classAxiom.getRelationshipGroup());
});
}).collect(Collectors.toSet());
} catch (IOException e) {
throw new SnowowlRuntimeException(e);
}
}
use of com.b2international.index.query.Expressions.ExpressionBuilder in project snow-owl by b2ihealthcare.
the class SnomedEclRefinementEvaluator method evalAxiomsWithValue.
private Promise<Collection<Property>> evalAxiomsWithValue(BranchContext context, Set<String> focusConceptIds, Collection<String> typeIds, RelationshipValue value, SearchResourceRequest.Operator operator) {
// search existing axioms defined for the given set of conceptIds
ExpressionBuilder axiomFilter = Expressions.builder();
if (typeIds != null) {
axiomFilter.filter(typeIds(typeIds));
}
switch(operator) {
case EQUALS:
axiomFilter.filter(values(List.of(value)));
break;
case GREATER_THAN:
axiomFilter.filter(valueGreaterThan(value, false));
break;
case GREATER_THAN_EQUALS:
axiomFilter.filter(valueGreaterThan(value, true));
break;
case LESS_THAN:
axiomFilter.filter(valueLessThan(value, false));
break;
case LESS_THAN_EQUALS:
axiomFilter.filter(valueLessThan(value, true));
break;
case NOT_EQUALS:
axiomFilter.mustNot(values(List.of(value)));
break;
default:
throw new IllegalStateException("Unexpected operator '" + operator + "'.");
}
ExpressionBuilder activeOwlAxiomMemberQuery = Expressions.builder().filter(active()).filter(Expressions.nestedMatch(SnomedRefSetMemberIndexEntry.Fields.CLASS_AXIOM_RELATIONSHIP, axiomFilter.build()));
if (focusConceptIds != null) {
activeOwlAxiomMemberQuery.filter(SnomedRefSetMemberIndexEntry.Expressions.referencedComponentIds(focusConceptIds));
}
final Query<SnomedRefSetMemberIndexEntry> activeAxiomStatementsQuery = Query.select(SnomedRefSetMemberIndexEntry.class).where(activeOwlAxiomMemberQuery.build()).limit(context.service(RepositoryConfiguration.class).getIndexConfiguration().getResultWindow()).build();
final Set<Property> axiomProperties = newHashSet();
context.service(RevisionSearcher.class).stream(activeAxiomStatementsQuery).forEach(chunk -> {
chunk.stream().filter(owlMember -> !CompareUtils.isEmpty(owlMember.getClassAxiomRelationships())).forEachOrdered(owlMember -> {
owlMember.getClassAxiomRelationships().stream().filter(r -> typeIds == null || typeIds.contains(r.getTypeId())).filter(r -> r.getValueAsObject().matches(operator, value)).map(r -> new Property(owlMember.getReferencedComponentId(), r.getTypeId(), r.getValueAsObject().toObject(), r.getRelationshipGroup())).forEachOrdered(axiomProperties::add);
});
});
return Promise.immediate(axiomProperties);
}
use of com.b2international.index.query.Expressions.ExpressionBuilder in project snow-owl by b2ihealthcare.
the class SearchMergeRequest method doExecute.
@Override
public Merges doExecute(RepositoryContext context) {
final ExpressionBuilder queryBuilder = Expressions.builder();
// add mergerequest type filter
queryBuilder.filter(RemoteJobEntry.Expressions.matchRequestType(ImmutableSet.of(BranchRebaseRequest.class.getSimpleName(), BranchMergeRequest.class.getSimpleName())));
if (containsKey(OptionKey.SOURCE)) {
queryBuilder.filter(RemoteJobEntry.Expressions.matchParameter(SOURCE_FIELD, getCollection(OptionKey.SOURCE, String.class)));
}
if (containsKey(OptionKey.TARGET)) {
queryBuilder.filter(RemoteJobEntry.Expressions.matchParameter(TARGET_FIELD, getCollection(OptionKey.TARGET, String.class)));
}
if (containsKey(OptionKey.STATUS)) {
queryBuilder.filter(RemoteJobEntry.Expressions.matchParameter(STATUS_FIELD, getCollection(OptionKey.STATUS, String.class)));
}
final RemoteJobs jobs = context.service(RemoteJobTracker.class).search(queryBuilder.build(), Integer.MAX_VALUE);
final ObjectMapper mapper = context.service(ObjectMapper.class);
final List<Merge> items = jobs.stream().map(job -> createMergefromJobEntry(job, mapper)).collect(Collectors.toList());
return new Merges(items, jobs.getSearchAfter(), jobs.getLimit(), jobs.getTotal());
}
Aggregations