Search in sources :

Example 36 with ExpressionBuilder

use of com.b2international.index.query.Expressions.ExpressionBuilder in project snow-owl by b2ihealthcare.

the class ReasonerTaxonomyBuilder method addActiveAdditionalGroupedRelationships.

public ReasonerTaxonomyBuilder addActiveAdditionalGroupedRelationships(final RevisionSearcher searcher) {
    entering("Registering active additional grouped relationships using revision searcher");
    final ExpressionBuilder whereExpressionBuilder = Expressions.builder().filter(active()).filter(relationshipGroup(1, Integer.MAX_VALUE)).filter(characteristicTypeId(Concepts.ADDITIONAL_RELATIONSHIP));
    if (!excludedModuleIds.isEmpty()) {
        whereExpressionBuilder.mustNot(modules(excludedModuleIds));
    }
    addRelationships(searcher, whereExpressionBuilder, additionalGroupedRelationships);
    leaving("Registering active additional grouped relationships using revision searcher");
    return this;
}
Also used : ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder)

Example 37 with ExpressionBuilder

use of com.b2international.index.query.Expressions.ExpressionBuilder in project snow-owl by b2ihealthcare.

the class ReasonerTaxonomyBuilder method addNeverGroupedTypeIds.

public ReasonerTaxonomyBuilder addNeverGroupedTypeIds(final RevisionSearcher searcher) {
    entering("Registering 'never grouped' type IDs using revision searcher");
    final ExpressionBuilder whereExpressionBuilder = Expressions.builder().filter(SnomedRefSetMemberIndexEntry.Expressions.active()).filter(SnomedRefSetMemberIndexEntry.Expressions.refsetId(Concepts.REFSET_MRCM_ATTRIBUTE_DOMAIN_INTERNATIONAL)).filter(SnomedRefSetMemberIndexEntry.Expressions.mrcmGrouped(false));
    if (!excludedModuleIds.isEmpty()) {
        whereExpressionBuilder.mustNot(modules(excludedModuleIds));
    }
    final LongList fragments = PrimitiveLists.newLongArrayListWithExpectedSize(SCROLL_LIMIT);
    Query.select(String.class).from(SnomedRefSetMemberIndexEntry.class).fields(SnomedRefSetMemberIndexEntry.Fields.REFERENCED_COMPONENT_ID).where(whereExpressionBuilder.build()).sortBy(SortBy.builder().sortByField(SnomedRefSetMemberIndexEntry.Fields.REFERENCED_COMPONENT_ID, Order.ASC).sortByField(SnomedRefSetMemberIndexEntry.Fields.ID, Order.ASC).build()).limit(SCROLL_LIMIT).build().stream(searcher).forEachOrdered(hits -> {
        for (final String referencedComponentId : hits) {
            fragments.add(Long.parseLong(referencedComponentId));
        }
        neverGroupedTypeIds.addAll(fragments);
        fragments.clear();
    });
    leaving("Registering 'never grouped' type IDs using revision searcher");
    return this;
}
Also used : LongList(com.b2international.collections.longs.LongList) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder)

Example 38 with ExpressionBuilder

use of com.b2international.index.query.Expressions.ExpressionBuilder in project snow-owl by b2ihealthcare.

the class BranchSearchRequest method prepareQuery.

@Override
protected Expression prepareQuery(RepositoryContext context) {
    ExpressionBuilder queryBuilder = Expressions.builder();
    addIdFilter(queryBuilder, ids -> Expressions.matchAny(RevisionBranch.Fields.PATH, ids));
    if (containsKey(OptionKey.PARENT)) {
        queryBuilder.filter(Expressions.matchAny(RevisionBranch.Fields.PARENT_PATH, getCollection(OptionKey.PARENT, String.class)));
    }
    if (containsKey(OptionKey.NAME)) {
        queryBuilder.filter(Expressions.matchAny(RevisionBranch.Fields.NAME, getCollection(OptionKey.NAME, String.class)));
    }
    if (containsKey(OptionKey.BRANCH_ID)) {
        queryBuilder.filter(Expressions.matchAnyLong(RevisionBranch.Fields.ID, getCollection(OptionKey.BRANCH_ID, Long.class)));
    }
    return queryBuilder.build();
}
Also used : ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder)

Example 39 with ExpressionBuilder

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 DialectAliasFilter dialectAliasFilter) {
    final ListMultimap<String, String> languageMapping = SnomedDescriptionUtils.getLanguageMapping(context);
    final Multimap<String, String> languageRefSetsByAcceptabilityField = HashMultimap.create();
    final ExpressionBuilder dialectQuery = Expressions.builder();
    for (DialectAlias alias : dialectAliasFilter.getDialects()) {
        final Set<String> acceptabilityFields = getAcceptabilityFields(alias.getAcceptability());
        final Collection<String> languageReferenceSetIds = languageMapping.get(alias.getAlias());
        // empty acceptabilities or empty language reference set IDs mean that none of the provided values were valid so no match should be returned
        if (acceptabilityFields.isEmpty() || languageReferenceSetIds.isEmpty()) {
            return Promise.immediate(Expressions.matchNone());
        }
        for (String acceptabilityField : acceptabilityFields) {
            languageRefSetsByAcceptabilityField.putAll(acceptabilityField, languageReferenceSetIds);
        }
    }
    languageRefSetsByAcceptabilityField.asMap().forEach((key, values) -> {
        Operator op = Operator.fromString(dialectAliasFilter.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 dialectAliasFilter operator '%s'", dialectAliasFilter.getOp());
        }
    });
    return Promise.immediate(dialectQuery.build());
}
Also used : NotImplementedException(com.b2international.commons.exceptions.NotImplementedException) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder)

Example 40 with ExpressionBuilder

use of com.b2international.index.query.Expressions.ExpressionBuilder in project snow-owl by b2ihealthcare.

the class DefaultRevisionIndex method purge.

private void purge(Writer writer, final RevisionBranchRef refToPurge, Set<Class<? extends Revision>> typesToPurge) throws IOException {
    // if nothing to purge return
    if (typesToPurge.isEmpty() || refToPurge.isEmpty()) {
        return;
    }
    final ExpressionBuilder purgeQuery = Expressions.builder();
    // purge only documents added to the selected branch
    for (RevisionSegment segmentToPurge : refToPurge.segments()) {
        purgeQuery.should(Expressions.builder().filter(segmentToPurge.toRangeExpression(Revision.Fields.CREATED)).filter(segmentToPurge.toRangeExpression(Revision.Fields.REVISED)).build());
    }
    for (Class<? extends Revision> revisionType : typesToPurge) {
        final String type = admin.mappings().getType(revisionType);
        admin().log().info("Purging '{}' revisions...", type);
        writer.bulkDelete(new BulkDelete<>(revisionType, purgeQuery.build()));
        writer.commit();
    }
}
Also used : ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder)

Aggregations

ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)47 Expressions (com.b2international.index.query.Expressions)17 Expression (com.b2international.index.query.Expression)6 List (java.util.List)6 Set (java.util.Set)6 BadRequestException (com.b2international.commons.exceptions.BadRequestException)5 NotImplementedException (com.b2international.commons.exceptions.NotImplementedException)5 Options (com.b2international.commons.options.Options)5 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)5 SearchResourceRequest (com.b2international.snowowl.core.request.SearchResourceRequest)5 Collection (java.util.Collection)5 Collectors (java.util.stream.Collectors)5 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)4 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)4 IOException (java.io.IOException)4 CompareUtils (com.b2international.commons.CompareUtils)3 Query (com.b2international.index.query.Query)3 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)3 BranchContext (com.b2international.snowowl.core.domain.BranchContext)3 RepositoryContext (com.b2international.snowowl.core.domain.RepositoryContext)3