Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a class to hold field capabilities for one index. #51721

Merged
merged 6 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Combine the add and merge methods in FieldCapabilities.Builder.
  • Loading branch information
jtibshirani committed Jan 31, 2020
commit fa6e4d15974d352575d01086f2e0bd4786ef5c4d
Original file line number Diff line number Diff line change
Expand Up @@ -290,35 +290,20 @@ static class Builder {
this.meta = new HashMap<>();
}

private void add(String index, boolean search, boolean agg) {
/**
* Collect the field capabilities for an index.
*/
void add(String index, boolean search, boolean agg, Map<String, String> meta) {
IndexCaps indexCaps = new IndexCaps(index, search, agg);
indiceList.add(indexCaps);
this.isSearchable &= search;
this.isAggregatable &= agg;
}

/**
* Collect capabilities of an index.
*/
void add(String index, boolean search, boolean agg, Map<String, String> meta) {
add(index, search, agg);
for (Map.Entry<String, String> entry : meta.entrySet()) {
this.meta.computeIfAbsent(entry.getKey(), key -> new HashSet<>())
.add(entry.getValue());
}
}

/**
* Merge another capabilities instance.
*/
void merge(String index, boolean search, boolean agg, Map<String, Set<String>> meta) {
add(index, search, agg);
for (Map.Entry<String, Set<String>> entry : meta.entrySet()) {
this.meta.computeIfAbsent(entry.getKey(), key -> new HashSet<>())
.addAll(entry.getValue());
}
}

List<String> getIndices() {
return indiceList.stream().map(c -> c.name).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private void innerMerge(Map<String, Map<String, FieldCapabilities.Builder>> resp
Map<String, FieldCapabilities.Builder> typeMap = responseMapBuilder.computeIfAbsent(field, f -> new HashMap<>());
FieldCapabilities.Builder builder = typeMap.computeIfAbsent(fieldCap.getType(),
key -> new FieldCapabilities.Builder(field, key));
builder.merge(indexName, fieldCap.isSearchable(), fieldCap.isAggregatable(), fieldCap.meta());
builder.add(indexName, fieldCap.isSearchable(), fieldCap.isAggregatable(), fieldCap.meta());
}
}
}