@Test void mapQueryRuleAttributeSearchReferencedAttribute() { QueryRule queryRule = mock(QueryRule.class); when(queryRule.getField()).thenReturn("attr"); when(queryRule.getValue()).thenReturn("val"); Attribute refIdAttribute = mock(Attribute.class); when(refIdAttribute.getDataType()).thenReturn(STRING); EntityType refEntityType = mock(EntityType.class); when(refEntityType.getIdAttribute()).thenReturn(refIdAttribute); when(documentIdGenerator.generateId(refIdAttribute)).thenReturn("refAttr"); Attribute attribute = mock(Attribute.class); when(attribute.hasRefEntity()).thenReturn(true); when(attribute.getRefEntity()).thenReturn(refEntityType); when(documentIdGenerator.generateId(attribute)).thenReturn("attr"); EntityType entityType = mock(EntityType.class); when(entityType.getIndexingDepth()).thenReturn(1); when(entityType.getAttributeByName("attr")).thenReturn(attribute); QueryBuilder queryBuilder = queryClauseSearchGenerator.mapQueryRule(queryRule, entityType); QueryBuilder expectedQueryBuilder = QueryBuilders.nestedQuery( "attr", QueryBuilders.matchQuery("attr.refAttr", "val"), ScoreMode.Avg); assertQueryBuilderEquals(expectedQueryBuilder, queryBuilder); }
QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { if (queryRule.getValue() == null) { throw new MolgenisQueryException(QUERY_VALUE_CANNOT_BE_NULL_MSG); } if (queryRule.getField() == null) { return createQueryClauseSearchAll(queryRule); } else { return createQueryClauseSearchAttribute(queryRule, entityType); } }
QueryClauseSearchGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { if (queryRule.getValue() == null) { throw new MolgenisQueryException(QUERY_VALUE_CANNOT_BE_NULL_MSG); } if (queryRule.getField() == null) { return createQueryClauseSearchAll(queryRule); } else { return createQueryClauseSearchAttribute(queryRule, entityType); } } }
QueryClauseSearchGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { if (queryRule.getValue() == null) { throw new MolgenisQueryException(QUERY_VALUE_CANNOT_BE_NULL_MSG); } if (queryRule.getField() == null) { return createQueryClauseSearchAll(queryRule); } else { return createQueryClauseSearchAttribute(queryRule, entityType); } } QueryClauseSearchGenerator(DocumentIdGenerator documentIdGenerator); }
QueryClauseSearchGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { if (queryRule.getValue() == null) { throw new MolgenisQueryException(QUERY_VALUE_CANNOT_BE_NULL_MSG); } if (queryRule.getField() == null) { return createQueryClauseSearchAll(queryRule); } else { return createQueryClauseSearchAttribute(queryRule, entityType); } } QueryClauseSearchGenerator(DocumentIdGenerator documentIdGenerator);  }
QueryClauseSearchGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { if (queryRule.getValue() == null) { throw new MolgenisQueryException(QUERY_VALUE_CANNOT_BE_NULL_MSG); } if (queryRule.getField() == null) { return createQueryClauseSearchAll(queryRule); } else { return createQueryClauseSearchAttribute(queryRule, entityType); } } QueryClauseSearchGenerator(DocumentIdGenerator documentIdGenerator);   }