From 11557084afc1e7ae2cce9e3035979c692daf659c Mon Sep 17 00:00:00 2001 From: edunn Date: Thu, 11 Jul 2024 11:44:14 -0700 Subject: [PATCH] reimplement field match methods currently only supports String and PdsProductIdentifier --- .../controllers/ProductsController.java | 6 +-- .../search/RegistrySearchRequestBuilder.java | 39 ++++++++++--------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/service/src/main/java/gov/nasa/pds/api/registry/controllers/ProductsController.java b/service/src/main/java/gov/nasa/pds/api/registry/controllers/ProductsController.java index a33955e8..ae543a26 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/controllers/ProductsController.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/controllers/ProductsController.java @@ -272,7 +272,7 @@ private HashMap 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 // because of compilation features, see @@ -297,7 +297,7 @@ private HashMap 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 // because of compilation features, see @@ -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); diff --git a/service/src/main/java/gov/nasa/pds/api/registry/search/RegistrySearchRequestBuilder.java b/service/src/main/java/gov/nasa/pds/api/registry/search/RegistrySearchRequestBuilder.java index caa2751f..59c884f2 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/search/RegistrySearchRequestBuilder.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/search/RegistrySearchRequestBuilder.java @@ -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 sortFieldNames,