Skip to content

Commit

Permalink
Consistent naming (opensearch-project#11733)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Brusic <[email protected]>
  • Loading branch information
brusic committed Apr 4, 2024
1 parent ea83026 commit 2ca6eed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public class AdjacencyMatrixAggregationBuilder extends AbstractAggregationBuilde

private static final ParseField SEPARATOR_FIELD = new ParseField("separator");
private static final ParseField FILTERS_FIELD = new ParseField("filters");

public static final ParseField SHOW_ONLY_INTERSECTING = new ParseField("show_only_intersecting");
private static final ParseField SHOW_ONLY_INTERSECTING = new ParseField("show_only_intersecting");

private List<KeyedFilter> filters;
private boolean showOnlyIntersecting = false;
Expand All @@ -86,7 +85,7 @@ public class AdjacencyMatrixAggregationBuilder extends AbstractAggregationBuilde
PARSER.declareString(AdjacencyMatrixAggregationBuilder::separator, SEPARATOR_FIELD);
PARSER.declareNamedObjects(AdjacencyMatrixAggregationBuilder::setFiltersAsList, KeyedFilter.PARSER, FILTERS_FIELD);
PARSER.declareBoolean(
AdjacencyMatrixAggregationBuilder::showOnlyIntersecting,
AdjacencyMatrixAggregationBuilder::setShowOnlyIntersecting,
AdjacencyMatrixAggregationBuilder.SHOW_ONLY_INTERSECTING
);
}
Expand Down Expand Up @@ -147,6 +146,22 @@ public AdjacencyMatrixAggregationBuilder(String name, String separator, Map<Stri
setFiltersAsMap(filters);
}

/**
* @param name
* the name of this aggregation
* @param filters
* the filters and their key to use with this aggregation.
* @param showOnlyIntersecting
* show only the buckets that intersection multiple documents
*/
public AdjacencyMatrixAggregationBuilder(
String name,
Map<String, QueryBuilder> filters,
boolean showOnlyIntersecting
) {
this(name, DEFAULT_SEPARATOR, filters, showOnlyIntersecting);
}

/**
* @param name
* the name of this aggregation
Expand Down Expand Up @@ -218,7 +233,7 @@ private AdjacencyMatrixAggregationBuilder setFiltersAsList(List<KeyedFilter> fil
return this;
}

public AdjacencyMatrixAggregationBuilder showOnlyIntersecting(boolean showOnlyIntersecting) {
public AdjacencyMatrixAggregationBuilder setShowOnlyIntersecting(boolean showOnlyIntersecting) {
this.showOnlyIntersecting = showOnlyIntersecting;
return this;
}
Expand Down Expand Up @@ -268,7 +283,7 @@ protected AdjacencyMatrixAggregationBuilder doRewrite(QueryRewriteContext queryS
if (modified) {
return new AdjacencyMatrixAggregationBuilder(name).separator(separator)
.setFiltersAsList(rewrittenFilters)
.showOnlyIntersecting(showOnlyIntersecting);
.setShowOnlyIntersecting(showOnlyIntersecting);
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ public void testShowOnlyIntersecting() {
original.put("aaa", new MatchNoneQueryBuilder());
AdjacencyMatrixAggregationBuilder builder;
builder = new AdjacencyMatrixAggregationBuilder("my-agg", "&", original, true);
assertEquals(true, builder.isShowOnlyIntersecting());
assertTrue(builder.isShowOnlyIntersecting());
}

public void testShowOnlyIntersectingAsFalse() {
Map<String, QueryBuilder> original = new HashMap<>();
original.put("bbb", new MatchNoneQueryBuilder());
original.put("aaa", new MatchNoneQueryBuilder());
AdjacencyMatrixAggregationBuilder builder;
builder = new AdjacencyMatrixAggregationBuilder("my-agg", original, false);
assertFalse(builder.isShowOnlyIntersecting());
}
}

0 comments on commit 2ca6eed

Please sign in to comment.