Search in sources :

Example 51 with Expression

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

the class SnomedEclEvaluationRequestTest method refinementWithConjunctionAndDisjunction.

@Test
public void refinementWithConjunctionAndDisjunction() throws Exception {
    generateDrugHierarchy();
    generateTisselKit();
    final Expression actual = eval(String.format("<%s:%s=%s OR (%s=%s AND %s=%s)", DRUG_ROOT, HAS_ACTIVE_INGREDIENT, INGREDIENT2, HAS_ACTIVE_INGREDIENT, INGREDIENT4, HAS_ACTIVE_INGREDIENT, INGREDIENT2));
    final Expression expected = Expressions.builder().should(and(descendantsOf(DRUG_ROOT), ids(Set.of(TRIPHASIL_TABLET)))).should(and(and(descendantsOf(DRUG_ROOT), ids(Set.of(TISSEL_KIT))), and(descendantsOf(DRUG_ROOT), ids(Set.of(TRIPHASIL_TABLET))))).build();
    assertEquals(expected, actual);
}
Also used : Expression(com.b2international.index.query.Expression) Test(org.junit.Test)

Example 52 with Expression

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

the class SearchIndexResourceRequest method doExecute.

@Override
protected final B doExecute(C context) throws IOException {
    final Searcher searcher = searcher(context);
    final Expression where = prepareQuery(context);
    // configure additional fields to load when subsetting the response
    List<String> fields = fields();
    if (!fields().isEmpty()) {
        fields = configureFieldsToLoad(fields);
    }
    final Hits<D> hits = searcher.search(Query.select(getSelect()).from(getFrom()).fields(fields).where(where).searchAfter(searchAfter()).limit(limit()).sortBy(querySortBy(context)).withScores(trackScores()).cached(cacheHits(context)).build());
    return toCollectionResource(context, hits);
}
Also used : Expression(com.b2international.index.query.Expression) Searcher(com.b2international.index.Searcher) RevisionSearcher(com.b2international.index.revision.RevisionSearcher)

Example 53 with Expression

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

the class DefaultOperationLockManager method getOrCreateLock.

private IOperationLock getOrCreateLock(DatastoreLockContext context, final DatastoreLockTarget target) {
    synchronized (syncObject) {
        final String repositoryId = target.getRepositoryId();
        final String branchPath = target.getBranchPath();
        final Expression searchExpression = Expressions.builder().filter(DatastoreLockIndexEntry.Expressions.repositoryId(repositoryId)).filter(DatastoreLockIndexEntry.Expressions.branchPath(branchPath)).build();
        final DatastoreLockIndexEntry existingLockEntry = Iterables.getOnlyElement(search(searchExpression, 2), null);
        final IOperationLock lock;
        if (existingLockEntry == null) {
            lastAssignedId = assignedIds.nextClearBit(lastAssignedId);
            final String lockId = Integer.toString(lastAssignedId);
            lock = createLock(lastAssignedId, target);
            final DatastoreLockIndexEntry newEntry = buildIndexEntry(lockId, branchPath, repositoryId, context);
            put(newEntry);
            assignedIds.set(lastAssignedId);
            /* 
				 * XXX (apeteri): this makes the lock manager revisit low IDs after every 128 issued locks, but 
				 * it can still assign a number over 128 if all of the early ones are in use, since the BitSet grows unbounded. 
				 */
            lastAssignedId = lastAssignedId % EXPECTED_LOCKS;
        } else {
            lock = new OperationLock(Integer.parseInt(existingLockEntry.getId()), target);
        }
        lock.acquire(context);
        return lock;
    }
}
Also used : Expression(com.b2international.index.query.Expression)

Example 54 with Expression

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

the class SnomedEclEvaluationRequestPropertyFilterTest method preferredIn.

@Test
public void preferredIn() throws Exception {
    indexRevision(MAIN, SnomedDescriptionIndexEntry.builder().id(generateDescriptionId()).active(true).moduleId(Concepts.MODULE_SCT_CORE).term("Clinical finding").conceptId(Concepts.ROOT_CONCEPT).typeId(Concepts.TEXT_DEFINITION).preferredIn(Set.of(Concepts.REFSET_LANGUAGE_TYPE_UK)).acceptableIn(Set.of(Concepts.REFSET_LANGUAGE_TYPE_US)).build());
    indexRevision(MAIN, SnomedDescriptionIndexEntry.builder().id(generateDescriptionId()).active(true).moduleId(Concepts.MODULE_SCT_CORE).term("Clinical finding").conceptId(Concepts.SUBSTANCE).typeId(Concepts.TEXT_DEFINITION).preferredIn(Set.of(Concepts.REFSET_LANGUAGE_TYPE_US)).acceptableIn(Set.of(Concepts.REFSET_LANGUAGE_TYPE_UK)).build());
    final Expression actual = eval("* {{ preferredIn = " + Concepts.REFSET_LANGUAGE_TYPE_UK + " }}");
    final Expression expected = SnomedDocument.Expressions.ids(List.of(Concepts.ROOT_CONCEPT));
    assertEquals(expected, actual);
}
Also used : Expression(com.b2international.index.query.Expression) Test(org.junit.Test)

Example 55 with Expression

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

the class SnomedEclEvaluationRequestPropertyFilterTest method conceptEffectiveTime.

@Test
public void conceptEffectiveTime() throws Exception {
    indexRevision(MAIN, SnomedConceptDocument.builder().id(Concepts.FINDING_SITE).active(true).released(true).effectiveTime(EffectiveTimes.getEffectiveTime("20210731", DateFormats.SHORT)).moduleId(Concepts.MODULE_SCT_CORE).build());
    indexRevision(MAIN, SnomedConceptDocument.builder().id(Concepts.HAS_ACTIVE_INGREDIENT).active(true).released(true).effectiveTime(EffectiveTimes.getEffectiveTime("20020131", DateFormats.SHORT)).moduleId(Concepts.MODULE_SCT_CORE).build());
    Expression expected = SnomedDocument.Expressions.effectiveTime(EffectiveTimes.getEffectiveTime("20210731", DateFormats.SHORT));
    Expression actual = eval("* {{ c effectiveTime = \"20210731\" }}");
    assertEquals(expected, actual);
}
Also used : Expression(com.b2international.index.query.Expression) Test(org.junit.Test)

Aggregations

Expression (com.b2international.index.query.Expression)151 Test (org.junit.Test)142 BaseRevisionIndexTest (com.b2international.index.revision.BaseRevisionIndexTest)8 Ignore (org.junit.Ignore)5 Expressions (com.b2international.index.query.Expressions)2 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)2 RevisionData (com.b2international.index.revision.RevisionFixtures.RevisionData)2 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)2 BranchContext (com.b2international.snowowl.core.domain.BranchContext)2 Options (com.b2international.commons.options.Options)1 BulkUpdate (com.b2international.index.BulkUpdate)1 Searcher (com.b2international.index.Searcher)1 Query (com.b2international.index.query.Query)1 RangeData (com.b2international.index.revision.RevisionFixtures.RangeData)1 Ecl (com.b2international.snomed.ecl.Ecl)1 Any (com.b2international.snomed.ecl.ecl.Any)1 EclConceptReference (com.b2international.snomed.ecl.ecl.EclConceptReference)1 ExpressionConstraint (com.b2international.snomed.ecl.ecl.ExpressionConstraint)1 NestedExpression (com.b2international.snomed.ecl.ecl.NestedExpression)1 ResourceURI (com.b2international.snowowl.core.ResourceURI)1