Skip to content

Commit

Permalink
added ADDITIONAL_IDENTIFIERS
Browse files Browse the repository at this point in the history
  • Loading branch information
StigNorland committed Nov 24, 2023
1 parent 1c41737 commit a201765
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"properties": {
"publicationInstance": {
"type": "nested"
"type": "nested",
"include_in_parent": true
},
"organizations": {
"type": "nested",
Expand All @@ -12,7 +13,10 @@
}
},
"associatedArtifacts": {
"type": "nested"
"type": "nested",
"include_in_parent": true
}
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,8 @@ public static String readApiHost() {
generateSimpleAggregation(INSTANCE_TYPE, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_INSTANCE_TYPE_KEYWORD),
generateSimpleAggregation(CONTEXT_TYPE, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_TYPE_KEYWORD),
generateFundingSourceAggregation(),
generateTopLevelOrganizationAggregation2(),
// generateSimpleAggregation(ASSOCIATED_ARTIFACTS, ASSOCIATED_ARTIFACTS + DOT + TYPE + DOT + KEYWORD).,
// generateHasFileAggregation(),
generateObjectLabelsAggregation(TOP_LEVEL_ORGANIZATION, TOP_LEVEL_ORGANIZATIONS)
// generateIdAggregation(TOP_LEVEL_ORGANIZATION, TOP_LEVEL_ORGANIZATIONS)
generateObjectLabelsAggregation(TOP_LEVEL_ORGANIZATION, TOP_LEVEL_ORGANIZATIONS),
generateHasFileAggregation()
);

private static TermsAggregationBuilder generateSimpleAggregation(String term, String field) {
Expand All @@ -175,27 +172,6 @@ private static TermsAggregationBuilder generateFundingSourceAggregation() {
generateLabelsAggregation(jsonPath(FUNDINGS, SOURCE)));
}

private static TermsAggregationBuilder generateTopLevelOrganizationAggregation2() {
return
generateSimpleAggregation(TOP_LEVEL_ORGANIZATION, TOP_LEVEL_ORGANIZATIONS + DOT + ID + DOT + KEYWORD)
.subAggregation(
generateLabelsAggregation(TOP_LEVEL_ORGANIZATIONS));
}

private static NestedAggregationBuilder generateTopLevelAggregation() {
return
new NestedAggregationBuilder("test1", jsonPath(TOP_LEVEL_ORGANIZATIONS))
// .subAggregation(
.subAggregation(generateLabelsAggregation(jsonPath(TOP_LEVEL_ORGANIZATIONS)));
}

private static TermsAggregationBuilder generateTopLevelOrganizationAggregation() {
return
new TermsAggregationBuilder("test2")
.field(jsonPath(TOP_LEVEL_ORGANIZATIONS, ID, KEYWORD))
.subAggregation(generateLabelsAggregation(jsonPath(TOP_LEVEL_ORGANIZATIONS))
);
}

private static TermsAggregationBuilder generateIdAggregation(String object) {
return new TermsAggregationBuilder(ID)
Expand All @@ -204,11 +180,6 @@ private static TermsAggregationBuilder generateIdAggregation(String object) {
.subAggregation(generateLabelsAggregation(object));
}

// private static TermsAggregationBuilder generateIdAggregation(String displayName, String path) {
// return generateSimpleAggregation(displayName, jsonPath(path, ID, KEYWORD))
// .size(Defaults.DEFAULT_AGGREGATION_SIZE)
// .subAggregation(generateLabelsAggregation(path));
// }

private static NestedAggregationBuilder generateLabelsAggregation(String jsonPath) {
var nestedAggregation = new NestedAggregationBuilder(LABELS, jsonPath(jsonPath, LABELS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,18 @@ public static JsonNode formatAggregations(JsonNode aggregations) {
.orElse(fieldName.replaceFirst(WORD_ENDING_WITH_HASHTAG_REGEX, ""));

var value = nodeEntry.getValue();
if (value.at("/id/buckets").isArray()) {
value = value.at("/id/buckets");
}
if (value.has("buckets")) {
value = value.at("/buckets");
}
if (LABELS.equals(newName)) {
outputAggregationNode.set(newName, formatLabels(value));
} else if (NAME.equals(newName)) {
outputAggregationNode.set(LABELS, formatName(value));
} else if (value.isValueNode()) {
outputAggregationNode.set(newName, value);
} else if (value.has("buckets")) {
var bucket = value.get("buckets");
var arrayNode = objectMapperWithEmpty.createArrayNode();
bucket.forEach(element -> arrayNode.add(formatAggregations(element)));
outputAggregationNode.set(newName, arrayNode);
} else if (value.isArray()) {
var arrayNode = objectMapperWithEmpty.createArrayNode();
value.forEach(element -> arrayNode.add(formatAggregations(element)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void shouldReturnInstanceTypeAggregationWithDocCountTwo()
var query = queryWithTermAndAggregation(SEARCH_ALL, IMPORT_CANDIDATES_AGGREGATIONS);

var response = searchClient.searchWithSearchDocumentQuery(query, indexName);
var docCount = response.getAggregations().get("type").get("buckets").get(0).get("docCount").asInt();
var docCount = response.getAggregations().get("instanceType").get("buckets").get(0).get("docCount").asInt();
assertThat(docCount, is(equalTo(1)));
}

Expand All @@ -261,8 +261,8 @@ void shouldFilterDocumentsWithFiles()
addDocumentsToIndex("imported_candidate_from_index.json", "not_imported_candidate_from_index.json");

var query = queryWithTermAndAggregation(
"(associatedArtifacts.type:\"PublishedFile\")AND(associatedArtifacts.administrativeAgreement:\"false\")",
IMPORT_CANDIDATES_AGGREGATIONS);
"(associatedArtifacts.type:\"PublishedFile\")AND(associatedArtifacts"
+ ".administrativeAgreement:\"false\")", IMPORT_CANDIDATES_AGGREGATIONS);

var response = searchClient.searchWithSearchDocumentQuery(query, indexName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ void searchWithUriReturnsOpenSearchAwsResponse(URI uri) throws ApiGatewayExcepti
)
);

assertThat(query.getValue(SIZE).as(), is(equalTo(pagedSearchResourceDto.hits().size())));
assertThat(query.getValue(SIZE).as(), is(equalTo(pagedSearchResourceDto.totalHits())));
assertThat(pagedSearchResourceDto.hits().size(), is(equalTo(query.getValue(SIZE).as())));
assertThat(pagedSearchResourceDto.totalHits(), is(equalTo(query.getValue(SIZE).as())));
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"properties": {
"publicationInstance": {
"type": "nested"
"type": "nested",
"include_in_parent": true
},
"organizations": {
"type": "nested",
Expand All @@ -12,7 +13,8 @@
}
},
"associatedArtifacts": {
"type": "nested"
"type": "nested",
"include_in_parent": true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
"properties": {
"topLevelOrganizations": {
"type": "nested",
"include_in_parent": true,
"properties": {
"labels": {
"include_in_parent": true,
"type": "nested"
}
}
Expand Down

0 comments on commit a201765

Please sign in to comment.