Search in sources :

Example 1 with SnomedRelationshipSearchRequestBuilder

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;
    }
}
Also used : PolymorphicDispatcher(org.eclipse.xtext.util.PolymorphicDispatcher) Query(com.b2international.index.query.Query) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) Promise(com.b2international.snowowl.core.events.util.Promise) ID(com.b2international.index.revision.Revision.Fields.ID) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) SnomedDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Options(com.b2international.commons.options.Options) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) com.b2international.snomed.ecl.ecl(com.b2international.snomed.ecl.ecl) RepositoryConfiguration(com.b2international.snowowl.core.config.RepositoryConfiguration) CompareUtils(com.b2international.commons.CompareUtils) com.google.common.collect(com.google.common.collect) ResourceURI(com.b2international.snowowl.core.ResourceURI) BadRequestException(com.b2international.commons.exceptions.BadRequestException) Function(com.google.common.base.Function) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) RelationshipValue(com.b2international.snowowl.snomed.core.domain.RelationshipValue) Collection(java.util.Collection) SnomedRelationshipSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedRelationshipSearchRequestBuilder) DataType(com.b2international.snowowl.snomed.core.domain.refset.DataType) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) Trees(com.b2international.snowowl.snomed.core.tree.Trees) SearchResourceRequest(com.b2international.snowowl.core.request.SearchResourceRequest) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Expressions(com.b2international.index.query.Expressions) Expressions.active(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument.Expressions.active) Entry(java.util.Map.Entry) Expression(com.b2international.index.query.Expression) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) BranchContext(com.b2international.snowowl.core.domain.BranchContext) Fields(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Fields) Expressions(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedRelationshipSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedRelationshipSearchRequestBuilder) Collection(java.util.Collection) RepositoryConfiguration(com.b2international.snowowl.core.config.RepositoryConfiguration)

Aggregations

CompareUtils (com.b2international.commons.CompareUtils)1 BadRequestException (com.b2international.commons.exceptions.BadRequestException)1 Options (com.b2international.commons.options.Options)1 Expression (com.b2international.index.query.Expression)1 Expressions (com.b2international.index.query.Expressions)1 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)1 Query (com.b2international.index.query.Query)1 ID (com.b2international.index.revision.Revision.Fields.ID)1 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)1 com.b2international.snomed.ecl.ecl (com.b2international.snomed.ecl.ecl)1 ResourceURI (com.b2international.snowowl.core.ResourceURI)1 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)1 RepositoryConfiguration (com.b2international.snowowl.core.config.RepositoryConfiguration)1 BranchContext (com.b2international.snowowl.core.domain.BranchContext)1 Promise (com.b2international.snowowl.core.events.util.Promise)1 SearchResourceRequest (com.b2international.snowowl.core.request.SearchResourceRequest)1 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)1 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)1 RelationshipValue (com.b2international.snowowl.snomed.core.domain.RelationshipValue)1 DataType (com.b2international.snowowl.snomed.core.domain.refset.DataType)1