Search in sources :

Example 6 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsTextNull.

@Test
public void generateOneQueryRuleNotEqualsTextNull() {
    String value = null;
    Query<Entity> q = new QueryImpl<>().not().eq(textAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(boolQuery().mustNot(existsQuery(textAttrName))));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryImpl(org.molgenis.data.support.QueryImpl) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 7 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsInt.

@Test
public void generateOneQueryRuleNotEqualsInt() {
    Integer value = 1;
    Query<Entity> q = new QueryImpl<>().not().eq(intAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(termQuery(intAttrName, value)));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryImpl(org.molgenis.data.support.QueryImpl) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 8 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsDateTime.

@Test
public void generateOneQueryRuleNotEqualsDateTime() throws ParseException {
    Instant value = Instant.parse("2015-05-22T06:12:13Z");
    Query<Entity> q = new QueryImpl<>().not().eq(dateTimeAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(termQuery(dateTimeAttrName, value.toString())));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryImpl(org.molgenis.data.support.QueryImpl) Instant(java.time.Instant) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 9 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsHtml.

@Test
public void generateOneQueryRuleNotEqualsHtml() {
    String value = "<h1>html</h1>";
    Query<Entity> q = new QueryImpl<>().not().eq(htmlAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(termQuery(htmlAttrName + '.' + FIELD_NOT_ANALYZED, value)));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryImpl(org.molgenis.data.support.QueryImpl) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 10 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsHyperlink.

@Test
public void generateOneQueryRuleNotEqualsHyperlink() {
    String value = "http://www.website.com/";
    Query<Entity> q = new QueryImpl<>().not().eq(hyperlinkAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(termQuery(hyperlinkAttrName + '.' + FIELD_NOT_ANALYZED, value)));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryImpl(org.molgenis.data.support.QueryImpl) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Aggregations

QueryImpl (org.molgenis.data.support.QueryImpl)98 Test (org.testng.annotations.Test)70 DynamicEntity (org.molgenis.data.support.DynamicEntity)37 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)36 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)36 EntityType (org.molgenis.data.meta.model.EntityType)28 Attribute (org.molgenis.data.meta.model.Attribute)25 Entity (org.molgenis.data.Entity)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 Stream (java.util.stream.Stream)7 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)7 AggregateQueryImpl (org.molgenis.data.support.AggregateQueryImpl)7 Objects.requireNonNull (java.util.Objects.requireNonNull)6 QueryRule (org.molgenis.data.QueryRule)6 AggregateQuery (org.molgenis.data.aggregation.AggregateQuery)6 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)6 BeforeMethod (org.testng.annotations.BeforeMethod)6 Instant (java.time.Instant)5 LocalDate (java.time.LocalDate)5 Operator (org.molgenis.data.QueryRule.Operator)5