@Test void testNestedQueryBuilderSizeOne() { EntityType entityType = when(mock(EntityType.class).getIndexingDepth()).thenReturn(1).getMock(); String fieldName = "attribute"; String queryValue = "value"; QueryBuilder queryBuilder = termQuery(fieldName, queryValue); Attribute attribute = mock(Attribute.class); QueryBuilder nestedQueryBuilder = queryGenerator.nestedQueryBuilder(entityType, singletonList(attribute), queryBuilder); assertQueryBuilderEquals(nestedQueryBuilder, queryBuilder); }
QueryBuilder nestedQueryBuilder( EntityType entityType, List<Attribute> attributePath, QueryBuilder queryBuilder) { validateIndexingDepth(entityType, attributePath); QueryBuilder nestedQueryBuilder = queryBuilder; if (attributePath.size() > 1) { List<String> fieldNamePath = attributePath.stream().map(this::getQueryFieldName).collect(toList()); for (int i = attributePath.size() - 1; i > 0; --i) { String path = String.join(".", fieldNamePath.subList(0, i)); nestedQueryBuilder = QueryBuilders.nestedQuery(path, nestedQueryBuilder, ScoreMode.Avg); } } return nestedQueryBuilder; }
BaseQueryClauseGenerator implements QueryClauseGenerator { QueryBuilder nestedQueryBuilder( EntityType entityType, List<Attribute> attributePath, QueryBuilder queryBuilder) { validateIndexingDepth(entityType, attributePath); QueryBuilder nestedQueryBuilder = queryBuilder; if (attributePath.size() > 1) { List<String> fieldNamePath = attributePath.stream().map(this::getQueryFieldName).collect(toList()); for (int i = attributePath.size() - 1; i > 0; --i) { String path = String.join(".", fieldNamePath.subList(0, i)); nestedQueryBuilder = QueryBuilders.nestedQuery(path, nestedQueryBuilder, ScoreMode.Avg); } } return nestedQueryBuilder; } }
BaseQueryClauseGenerator implements QueryClauseGenerator { QueryBuilder nestedQueryBuilder( EntityType entityType, List<Attribute> attributePath, QueryBuilder queryBuilder) { validateIndexingDepth(entityType, attributePath); QueryBuilder nestedQueryBuilder = queryBuilder; if (attributePath.size() > 1) { List<String> fieldNamePath = attributePath.stream().map(this::getQueryFieldName).collect(toList()); for (int i = attributePath.size() - 1; i > 0; --i) { String path = String.join(".", fieldNamePath.subList(0, i)); nestedQueryBuilder = QueryBuilders.nestedQuery(path, nestedQueryBuilder, ScoreMode.Avg); } } return nestedQueryBuilder; } BaseQueryClauseGenerator(DocumentIdGenerator documentIdGenerator, Operator operator); }
BaseQueryClauseGenerator implements QueryClauseGenerator { QueryBuilder nestedQueryBuilder( EntityType entityType, List<Attribute> attributePath, QueryBuilder queryBuilder) { validateIndexingDepth(entityType, attributePath); QueryBuilder nestedQueryBuilder = queryBuilder; if (attributePath.size() > 1) { List<String> fieldNamePath = attributePath.stream().map(this::getQueryFieldName).collect(toList()); for (int i = attributePath.size() - 1; i > 0; --i) { String path = String.join(".", fieldNamePath.subList(0, i)); nestedQueryBuilder = QueryBuilders.nestedQuery(path, nestedQueryBuilder, ScoreMode.Avg); } } return nestedQueryBuilder; } BaseQueryClauseGenerator(DocumentIdGenerator documentIdGenerator, Operator operator); @Override Operator getOperator(); @Override QueryBuilder createQueryClause(QueryRule queryRule, EntityType entityType); }
BaseQueryClauseGenerator implements QueryClauseGenerator { QueryBuilder nestedQueryBuilder( EntityType entityType, List<Attribute> attributePath, QueryBuilder queryBuilder) { validateIndexingDepth(entityType, attributePath); QueryBuilder nestedQueryBuilder = queryBuilder; if (attributePath.size() > 1) { List<String> fieldNamePath = attributePath.stream().map(this::getQueryFieldName).collect(toList()); for (int i = attributePath.size() - 1; i > 0; --i) { String path = String.join(".", fieldNamePath.subList(0, i)); nestedQueryBuilder = QueryBuilders.nestedQuery(path, nestedQueryBuilder, ScoreMode.Avg); } } return nestedQueryBuilder; } BaseQueryClauseGenerator(DocumentIdGenerator documentIdGenerator, Operator operator); @Override Operator getOperator(); @Override QueryBuilder createQueryClause(QueryRule queryRule, EntityType entityType);  }