Skip to content

Commit

Permalink
reimplement field match methods
Browse files Browse the repository at this point in the history
currently only supports String and PdsProductIdentifier
  • Loading branch information
alexdunnjpl committed Jul 11, 2024
1 parent 323e3b3 commit 1155708
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private HashMap<String, Object> getLidVid(PdsProductIdentifier identifier, List<


SearchRequest searchRequest =
registrySearchRequestBuilder.addLidvidMatch(identifier).fieldsFromStrings(fields).build();
registrySearchRequestBuilder.matchLidvid(identifier).fieldsFromStrings(fields).build();

// useless to detail here that the HashMap is parameterized <String, Object>
// because of compilation features, see
Expand All @@ -297,7 +297,7 @@ private HashMap<String, Object> getLatestLidVid(PdsProductIdentifier identifier,
new RegistrySearchRequestBuilder(this.registrySearchRequestBuilder);

SearchRequest searchRequest =
registrySearchRequestBuilder.addLidMatch(identifier).onlyLatest().fieldsFromStrings(fields).build();
registrySearchRequestBuilder.matchLid(identifier).onlyLatest().fieldsFromStrings(fields).build();

// useless to detail here that the HashMap is parameterized <String, Object>
// because of compilation features, see
Expand All @@ -324,7 +324,7 @@ private RawMultipleProductResponse getAllLidVid(PdsProductIdentifier identifier,
new RegistrySearchRequestBuilder(this.registrySearchRequestBuilder);

registrySearchRequestBuilder =
registrySearchRequestBuilder.addLidMatch(identifier).fieldsFromStrings(fields);
registrySearchRequestBuilder.matchLid(identifier).fieldsFromStrings(fields);

registrySearchRequestBuilder = registrySearchRequestBuilder.paginates(limit, sort, searchAfter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,32 +125,35 @@ public RegistrySearchRequestBuilder onlyLatest() {

}


public RegistrySearchRequestBuilder addLidvidMatch(PdsProductIdentifier identifier) {
// lidvid match
FieldValue lidvidFieldValue =
new FieldValue.Builder().stringValue(identifier.toString()).build();

MatchQuery lidvidMatch = new MatchQuery.Builder().field("_id").query(lidvidFieldValue).build();
/**
* Add a constraint that a given field name must match the given field value
* @param fieldName the name of the field in OpenSearch format
* @param value the value which must be present in the given field
*/
public RegistrySearchRequestBuilder mustMatch(String fieldName, String value) {
FieldValue fieldValue = new FieldValue.Builder().stringValue(value).build();
MatchQuery lidvidMatch = new MatchQuery.Builder().field(fieldName).query(fieldValue).build();

this.must.add(lidvidMatch.toQuery());

return this;

}
/**
* Add a constraint that a given field name must match the given field value
* @param fieldName the name of the field in OpenSearch format
* @param identifier the PDS identifier whose string representation must be present in the given field
*/
public RegistrySearchRequestBuilder mustMatch(String fieldName, PdsProductIdentifier identifier) {
return this.mustMatch(fieldName, identifier.toString());
}

public RegistrySearchRequestBuilder matchLidvid(PdsProductIdentifier identifier) {
return this.mustMatch("_id", identifier);
}

public RegistrySearchRequestBuilder addLidMatch(PdsProductIdentifier identifier) {
// lid match
FieldValue lidvidFieldValue =
new FieldValue.Builder().stringValue(identifier.getLid().toString()).build();

MatchQuery lidMatch = new MatchQuery.Builder().field("lid").query(lidvidFieldValue).build();

this.must.add(lidMatch.toQuery());

return this;

public RegistrySearchRequestBuilder matchLid(PdsProductIdentifier identifier) {
return this.mustMatch("lid", identifier);
}

public RegistrySearchRequestBuilder paginates(Integer pageSize, List<String> sortFieldNames,
Expand Down

0 comments on commit 1155708

Please sign in to comment.