use of com.b2international.index.query.Expressions.ExpressionBuilder in project snow-owl by b2ihealthcare.
the class SnomedRefSetSearchRequest method prepareQuery.
@Override
protected Expression prepareQuery(BranchContext context) {
final ExpressionBuilder queryBuilder = Expressions.builder();
addActiveClause(queryBuilder);
addReleasedClause(queryBuilder);
addIdFilter(queryBuilder, RevisionDocument.Expressions::ids);
addEclFilter(context, queryBuilder, SnomedSearchRequest.OptionKey.MODULE, SnomedDocument.Expressions::modules);
addEffectiveTimeClause(queryBuilder);
if (containsKey(OptionKey.TYPE)) {
queryBuilder.filter(refSetTypes(getCollection(OptionKey.TYPE, SnomedRefSetType.class)));
} else {
// always add type filter, so only concept docs with refset props will be returned
queryBuilder.filter(Expressions.exists(SnomedConceptDocument.Fields.REFSET_TYPE));
}
if (containsKey(OptionKey.REFERENCED_COMPONENT_TYPE)) {
queryBuilder.filter(referencedComponentTypes(getCollection(OptionKey.REFERENCED_COMPONENT_TYPE, String.class)));
}
if (containsKey(OptionKey.MAP_TARGET_COMPONENT_TYPE)) {
queryBuilder.filter(mapTargetComponentTypes(getCollection(OptionKey.MAP_TARGET_COMPONENT_TYPE, String.class)));
}
return queryBuilder.build();
}
use of com.b2international.index.query.Expressions.ExpressionBuilder in project snow-owl by b2ihealthcare.
the class RelationshipChangeSearchRequest method prepareQuery.
@Override
protected Expression prepareQuery(final RepositoryContext context) {
final ExpressionBuilder queryBuilder = Expressions.builder();
addClassificationIdClause(queryBuilder);
addSourceIdClause(queryBuilder);
addDestinationIdClause(queryBuilder);
return queryBuilder.build();
}
use of com.b2international.index.query.Expressions.ExpressionBuilder in project snow-owl by b2ihealthcare.
the class SnomedDescriptionSearchRequest method prepareQuery.
@Override
protected Expression prepareQuery(BranchContext context) {
if (containsKey(OptionKey.TERM) && get(OptionKey.TERM, TermFilter.class).getTerm().length() < 2) {
throw new BadRequestException("Description term must be at least 2 characters long.");
}
final ExpressionBuilder queryBuilder = Expressions.builder();
// Add (presumably) most selective filters first
addActiveClause(queryBuilder);
addReleasedClause(queryBuilder);
addLanguageFilter(queryBuilder);
addNamespaceFilter(queryBuilder);
addNamespaceConceptIdFilter(context, queryBuilder);
addActiveMemberOfClause(context, queryBuilder);
addMemberOfClause(context, queryBuilder);
addEclFilter(context, queryBuilder, OptionKey.LANGUAGE_REFSET, ids -> {
return Expressions.builder().should(preferredIn(ids)).should(acceptableIn(ids)).build();
});
addEclFilter(context, queryBuilder, OptionKey.ACCEPTABLE_IN, ids -> acceptableIn(ids));
addEclFilter(context, queryBuilder, OptionKey.PREFERRED_IN, ids -> preferredIn(ids));
// apply locale based filters
addFilter(queryBuilder, OptionKey.LANGUAGE_REFSET_LOCALES, ExtendedLocale.class, locales -> {
final List<String> languageRefSetIds = SnomedDescriptionUtils.getLanguageRefSetIds(context, (List<ExtendedLocale>) locales);
return Expressions.builder().should(preferredIn(languageRefSetIds)).should(acceptableIn(languageRefSetIds)).build();
});
addFilter(queryBuilder, OptionKey.ACCEPTABLE_IN_LOCALES, ExtendedLocale.class, locales -> {
final List<String> languageRefSetIds = SnomedDescriptionUtils.getLanguageRefSetIds(context, (List<ExtendedLocale>) locales);
return acceptableIn(languageRefSetIds);
});
addFilter(queryBuilder, OptionKey.PREFERRED_IN_LOCALES, ExtendedLocale.class, locales -> {
final List<String> languageRefSetIds = SnomedDescriptionUtils.getLanguageRefSetIds(context, (List<ExtendedLocale>) locales);
return preferredIn(languageRefSetIds);
});
addEffectiveTimeClause(queryBuilder);
addIdFilter(queryBuilder, RevisionDocument.Expressions::ids);
addEclFilter(context, queryBuilder, SnomedSearchRequest.OptionKey.MODULE, SnomedDocument.Expressions::modules);
addEclFilter(context, queryBuilder, OptionKey.CONCEPT, SnomedDescriptionIndexEntry.Expressions::concepts);
addEclFilter(context, queryBuilder, OptionKey.TYPE, SnomedDescriptionIndexEntry.Expressions::types);
addEclFilter(context, queryBuilder, OptionKey.CASE_SIGNIFICANCE, SnomedDescriptionIndexEntry.Expressions::caseSignificances);
if (containsKey(OptionKey.SEMANTIC_TAG)) {
queryBuilder.filter(SnomedDescriptionIndexEntry.Expressions.semanticTags(getCollection(OptionKey.SEMANTIC_TAG, String.class)));
}
if (containsKey(OptionKey.SEMANTIC_TAG_REGEX)) {
queryBuilder.filter(SnomedDescriptionIndexEntry.Expressions.semanticTagRegex(getString(OptionKey.SEMANTIC_TAG_REGEX)));
}
if (containsKey(OptionKey.TERM_REGEX)) {
final String regex = getString(OptionKey.TERM_REGEX);
queryBuilder.filter(SnomedDescriptionIndexEntry.Expressions.matchTermRegex(regex));
}
if (containsKey(OptionKey.TERM)) {
final TermFilter termFilter = get(OptionKey.TERM, TermFilter.class);
queryBuilder.must(toDescriptionTermQuery(termFilter));
}
return queryBuilder.build();
}
use of com.b2international.index.query.Expressions.ExpressionBuilder in project snow-owl by b2ihealthcare.
the class EquivalentConceptSetSearchRequest method prepareQuery.
@Override
protected Expression prepareQuery(final RepositoryContext context) {
final ExpressionBuilder queryBuilder = Expressions.builder();
addClassificationIdClause(queryBuilder);
addConceptIdClause(queryBuilder);
return queryBuilder.build();
}
use of com.b2international.index.query.Expressions.ExpressionBuilder in project snow-owl by b2ihealthcare.
the class Taxonomies method getStatements.
private static Collection<Object[]> getStatements(RevisionSearcher searcher, LongCollection conceptIds, String characteristicTypeId, boolean filterByConceptIds) throws IOException {
// merge stated relationships and OWL axiom relationships into a single array
ImmutableList.Builder<Object[]> isaStatementsBuilder = ImmutableList.builder();
final Set<String> concepts = LongSets.toStringSet(conceptIds);
ExpressionBuilder activeIsaRelationshipQuery = Expressions.builder().filter(active()).filter(typeId(Concepts.IS_A)).filter(characteristicTypeId(characteristicTypeId));
if (filterByConceptIds) {
activeIsaRelationshipQuery.filter(sourceIds(concepts)).filter(destinationIds(concepts));
}
final Query<String[]> activeStatedISARelationshipsQuery = Query.select(String[].class).from(SnomedRelationshipIndexEntry.class).fields(SnomedRelationshipIndexEntry.Fields.ID, SnomedRelationshipIndexEntry.Fields.SOURCE_ID, SnomedRelationshipIndexEntry.Fields.DESTINATION_ID).where(activeIsaRelationshipQuery.build()).limit(Integer.MAX_VALUE).build();
Hits<String[]> activeIsaRelationships = searcher.search(activeStatedISARelationshipsQuery);
activeIsaRelationships.forEach(activeIsaRelationship -> {
isaStatementsBuilder.add(new Object[] { activeIsaRelationship[0], Long.parseLong(activeIsaRelationship[1]), new long[] { Long.parseLong(activeIsaRelationship[2]) } });
});
activeIsaRelationships = null;
if (Concepts.STATED_RELATIONSHIP.equals(characteristicTypeId)) {
// search existing axioms defined for the given set of conceptIds
ExpressionBuilder activeOwlAxiomMemberQuery = Expressions.builder().filter(active());
if (filterByConceptIds) {
activeOwlAxiomMemberQuery.filter(SnomedRefSetMemberIndexEntry.Expressions.referencedComponentIds(concepts)).filter(Expressions.nestedMatch(SnomedRefSetMemberIndexEntry.Fields.CLASS_AXIOM_RELATIONSHIP, Expressions.builder().filter(typeId(Concepts.IS_A)).filter(destinationIds(concepts)).build()));
} else {
activeOwlAxiomMemberQuery.filter(Expressions.nestedMatch(SnomedRefSetMemberIndexEntry.Fields.CLASS_AXIOM_RELATIONSHIP, Expressions.builder().filter(typeId(Concepts.IS_A)).build()));
}
final Query<SnomedRefSetMemberIndexEntry> activeAxiomISARelationshipsQuery = Query.select(SnomedRefSetMemberIndexEntry.class).where(activeOwlAxiomMemberQuery.build()).limit(Integer.MAX_VALUE).build();
Hits<SnomedRefSetMemberIndexEntry> activeAxiomISARelationships = searcher.search(activeAxiomISARelationshipsQuery);
activeAxiomISARelationships.forEach(owlMember -> {
if (!CompareUtils.isEmpty(owlMember.getClassAxiomRelationships())) {
// XXX: breaks with a NumberFormatException if any of the IS A relationships has a value
long[] destinationIds = owlMember.getClassAxiomRelationships().stream().filter(classAxiom -> Concepts.IS_A.equals(classAxiom.getTypeId())).map(SnomedOWLRelationshipDocument::getDestinationId).mapToLong(Long::parseLong).toArray();
isaStatementsBuilder.add(new Object[] { owlMember.getId(), Long.parseLong(owlMember.getReferencedComponentId()), destinationIds });
}
});
activeAxiomISARelationships = null;
}
return isaStatementsBuilder.build();
}
Aggregations