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;
}
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;
}
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();
}
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());
}
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();
}
}
Aggregations