Search in sources :

Example 1 with Expression

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

the class SingleDocumentRevisionIndexSearchTest method searchWithFilter.

@Test
public void searchWithFilter() throws Exception {
    final RevisionData first = new RevisionData(STORAGE_KEY1, "field1", "field2");
    final RevisionData second = new RevisionData(STORAGE_KEY2, "field1", "field2");
    indexRevision(MAIN, first, second);
    final Expression expression = Expressions.builder().filter(Expressions.exactMatch("field1", "field1")).build();
    final Query<RevisionData> query = Query.select(RevisionData.class).where(expression).build();
    final Iterable<RevisionData> matches = search(MAIN, query);
    assertThat(matches).hasSize(2);
    assertThat(matches).containsAll(Lists.newArrayList(first, second));
}
Also used : Expression(com.b2international.index.query.Expression) RevisionData(com.b2international.index.revision.RevisionFixtures.RevisionData) Test(org.junit.Test)

Example 2 with Expression

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

the class SingleDocumentRevisionIndexSearchTest method searchWithMatchRange.

@Test
public void searchWithMatchRange() throws Exception {
    final RangeData first = new RangeData(STORAGE_KEY1, "field1", "field2", null, 2, 4);
    final RangeData second = new RangeData(STORAGE_KEY2, "field1", "field2", null, 3, 5);
    indexRevision(MAIN, first, second);
    final Expression expression = Expressions.builder().filter(Expressions.matchRange("from", 2, 3)).filter(Expressions.matchRange("to", 3, 4)).build();
    final Query<RangeData> query = Query.select(RangeData.class).where(expression).build();
    final Iterable<RangeData> matches = search(MAIN, query);
    assertThat(matches).hasSize(1);
    assertThat(matches).containsOnly(first);
}
Also used : Expression(com.b2international.index.query.Expression) RangeData(com.b2international.index.revision.RevisionFixtures.RangeData) Test(org.junit.Test)

Example 3 with Expression

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

the class BoolQueryTest method mergeDisjunctTermFilterClauses.

@Test
public void mergeDisjunctTermFilterClauses() throws Exception {
    String id1 = UUID.randomUUID().toString();
    String id2 = UUID.randomUUID().toString();
    String id3 = UUID.randomUUID().toString();
    String id4 = UUID.randomUUID().toString();
    Expression actual = Expressions.bool().filter(Expressions.exactMatch("id", id1)).filter(Expressions.matchAny("id", Set.of(id2, id3))).filter(Expressions.matchAny("id", Set.of(id3, id4))).build();
    assertEquals(Expressions.matchNone(), actual);
}
Also used : Expression(com.b2international.index.query.Expression) Test(org.junit.Test)

Example 4 with Expression

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

the class BoolQueryTest method mergeSingleTermShouldClauses.

@Test
public void mergeSingleTermShouldClauses() throws Exception {
    String id1 = UUID.randomUUID().toString();
    String id2 = UUID.randomUUID().toString();
    String id3 = UUID.randomUUID().toString();
    Expression actual = Expressions.bool().should(Expressions.exactMatch("id", id1)).should(Expressions.exactMatch("id", id2)).should(Expressions.exactMatch("id", id3)).build();
    assertEquals(Expressions.matchAny("id", Set.of(id1, id2, id3)), actual);
}
Also used : Expression(com.b2international.index.query.Expression) Test(org.junit.Test)

Example 5 with Expression

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

the class SnomedEclEvaluationRequestTest method refinementWithAttributeDisjunction.

@Test
public void refinementWithAttributeDisjunction() throws Exception {
    generateDrugHierarchy();
    generateTisselKit();
    final Expression actual = eval(String.format("<%s:%s=%s OR %s=%s", DRUG_ROOT, HAS_ACTIVE_INGREDIENT, INGREDIENT2, HAS_ACTIVE_INGREDIENT, INGREDIENT4));
    final Expression expected = Expressions.builder().should(and(descendantsOf(DRUG_ROOT), ids(Set.of(TRIPHASIL_TABLET)))).should(and(descendantsOf(DRUG_ROOT), ids(Set.of(TISSEL_KIT)))).build();
    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