use of com.b2international.snowowl.snomed.datastore.request.SnomedRelationshipSearchRequestBuilder in project snow-owl by b2ihealthcare.
the class SnomedEclRefinementEvaluator method evalStatements.
/**
* Executes a SNOMED CT Relationship search request using the given source, type, destination filters.
* If the groupedRelationshipsOnly boolean flag is <code>true</code>, then the search will match relationships that are grouped (their groupId is greater than or equals to <code>1</code>).
* @param context - the context where the search should happen
* @param sourceFilter - filter for relationship sources
* @param typeFilter - filter for relationship types
* @param destinationFilter - filter for relationship destinations
* @param groupedRelationshipsOnly - whether the search should consider grouped relationships only or not
* @return a {@link Promise} of {@link Collection} of {@link Property} objects that match the criteria
* @see SnomedRelationshipSearchRequestBuilder
*/
/*package*/
static Promise<Collection<Property>> evalStatements(final BranchContext context, final Collection<String> sourceFilter, final Collection<String> typeFilter, final Collection<String> destinationFilter, final boolean groupedRelationshipsOnly, final String expressionForm) {
final ImmutableList.Builder<String> fieldsToLoad = ImmutableList.builder();
fieldsToLoad.add(SnomedDocument.Fields.ID, SOURCE_ID, TYPE_ID, DESTINATION_ID);
if (groupedRelationshipsOnly) {
fieldsToLoad.add(RELATIONSHIP_GROUP);
}
SnomedRelationshipSearchRequestBuilder searchRelationships = SnomedRequests.prepareSearchRelationship().filterByActive(true).filterBySources(sourceFilter).filterByTypes(typeFilter).filterByDestinations(destinationFilter).filterByCharacteristicTypes(getCharacteristicTypes(expressionForm)).setEclExpressionForm(expressionForm).setFields(fieldsToLoad.build()).setLimit(context.service(RepositoryConfiguration.class).getIndexConfiguration().getResultWindow());
// if a grouping refinement, then filter relationships with group >= 1
if (groupedRelationshipsOnly) {
searchRelationships.filterByGroup(1, Integer.MAX_VALUE);
}
Promise<Collection<Property>> relationshipSearch = searchRelationships.transformAsync(context, req -> req.build(context.service(ResourceURI.class)), relationships -> relationships.stream().map(r -> new Property(r.getSourceId(), r.getTypeId(), r.getDestinationId(), r.getRelationshipGroup())));
if (Trees.STATED_FORM.equals(expressionForm)) {
final Set<Property> axiomStatements = evalAxiomStatements(context, groupedRelationshipsOnly, sourceFilter, typeFilter, destinationFilter);
return relationshipSearch.then(relationshipStatements -> ImmutableSet.<Property>builder().addAll(relationshipStatements).addAll(axiomStatements).build());
} else {
return relationshipSearch;
}
}
Aggregations