diff --git a/service/src/main/java/gov/nasa/pds/api/registry/business/Antlr4SearchListener.java b/service/src/main/java/gov/nasa/pds/api/registry/business/Antlr4SearchListener.java index 6c8fc5e1..43f51e84 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/business/Antlr4SearchListener.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/business/Antlr4SearchListener.java @@ -13,9 +13,9 @@ import org.antlr.v4.runtime.misc.ParseCancellationException; import org.opensearch.index.query.BoolQueryBuilder; -import org.opensearch.index.query.MatchQueryBuilder; -import org.opensearch.index.query.WildcardQueryBuilder; import org.opensearch.index.query.RangeQueryBuilder; +import org.opensearch.index.query.SimpleQueryStringBuilder; +import org.opensearch.index.query.TermQueryBuilder; import org.opensearch.index.query.QueryBuilder; public class Antlr4SearchListener extends SearchBaseListener @@ -50,7 +50,7 @@ public void exitQuery(SearchParser.QueryContext ctx) { for (QueryBuilder qb : musts) this.query.must(qb); for (QueryBuilder qb : nots) this.query.mustNot(qb); - for (QueryBuilder qb : shoulds) this.query.should(qb); + for (QueryBuilder qb : shoulds) this.query.filter(qb); } @Override @@ -88,7 +88,7 @@ public void exitGroup(SearchParser.GroupContext ctx) for (QueryBuilder qb : musts) group.must(qb); for (QueryBuilder qb : nots) group.mustNot(qb); - for (QueryBuilder qb : shoulds) group.should(qb); + for (QueryBuilder qb : shoulds) group.filter(qb); if (0 < depth) { @@ -147,7 +147,7 @@ else if (ctx.STRINGVAL() != null) if (this.operator == operation.eq || this.operator == operation.ne) { - comparator = new MatchQueryBuilder(left, right); + comparator = new TermQueryBuilder(left, right); } else { @@ -196,8 +196,7 @@ public void exitLikeComparison(SearchParser.LikeComparisonContext ctx) String right = ctx.STRINGVAL().getText(); right = right.substring(1, right.length() - 1); - - QueryBuilder comparator = new WildcardQueryBuilder(left, right); + QueryBuilder comparator = new SimpleQueryStringBuilder(right).field(left).fuzzyMaxExpansions(0); if("not".equalsIgnoreCase(ctx.getChild(1).getText())) { diff --git a/service/src/main/java/gov/nasa/pds/api/registry/business/PdsProductBusinessObject.java b/service/src/main/java/gov/nasa/pds/api/registry/business/PdsProductBusinessObject.java index 459cb80d..f14782b2 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/business/PdsProductBusinessObject.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/business/PdsProductBusinessObject.java @@ -59,6 +59,7 @@ public void setResponse (SearchHit hit, List fields) @SuppressWarnings("unchecked") public int setResponse(HitIterator hits, Summary summary, List fields, boolean onlySummary) { + int count; PdsProducts products = new PdsProducts(); Set uniqueProperties = new TreeSet(); @@ -72,13 +73,14 @@ public int setResponse(HitIterator hits, Summary summary, List fields, b products.getData().get(products.getData().size()-1).setProperties((Map)(Map)ProductBusinessObject.getFilteredProperties(kvp, null, null)); } } - + count = products.getData().size(); + if (onlySummary) products.setData(null); summary.setProperties(new ArrayList(uniqueProperties)); products.setSummary(summary); this.products = products; - return products.getData().size(); + return count; } @Override diff --git a/service/src/main/resources/application.properties.all b/service/src/main/resources/application.properties.all index 0c7d3977..1ffc694e 100644 --- a/service/src/main/resources/application.properties.all +++ b/service/src/main/resources/application.properties.all @@ -21,11 +21,11 @@ openSearch.host=es:9200 openSearch.registryIndex=registry openSearch.registryRefIndex=registry-refs openSearch.timeOutSeconds=60 -openSearch.username= -openSearch.password= -openSearch.ssl=false +openSearch.username=admin +openSearch.password=admin +openSearch.ssl=true # use only for development purpose, left it to true otherwise -openSearch.sslCertificateCNVerification=true +openSearch.sslCertificateCNVerification=false # Only show products with following archive statuses filter.archiveStatus=archived,certified,staged \ No newline at end of file diff --git a/service/src/test/java/gov/nasa/pds/api/registry/opensearch/Antlr4SearchListenerTest.java b/service/src/test/java/gov/nasa/pds/api/registry/opensearch/Antlr4SearchListenerTest.java index 1607def3..e3e2ed75 100644 --- a/service/src/test/java/gov/nasa/pds/api/registry/opensearch/Antlr4SearchListenerTest.java +++ b/service/src/test/java/gov/nasa/pds/api/registry/opensearch/Antlr4SearchListenerTest.java @@ -8,11 +8,11 @@ import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.ParseTreeWalker; import org.opensearch.index.query.BoolQueryBuilder; -import org.opensearch.index.query.MatchQueryBuilder; import org.opensearch.index.query.RangeQueryBuilder; -import org.opensearch.index.query.WildcardQueryBuilder; -import org.junit.Test; +import org.opensearch.index.query.SimpleQueryStringBuilder; +import org.opensearch.index.query.TermQueryBuilder; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.function.Executable; import gov.nasa.pds.api.registry.business.Antlr4SearchListener; @@ -62,9 +62,9 @@ public void testLikeWildcard() Assertions.assertEquals (query.must().size(), 1); Assertions.assertEquals (query.mustNot().size(), 0); Assertions.assertEquals (query.should().size(), 0); - Assertions.assertTrue (query.must().get(0) instanceof WildcardQueryBuilder); - Assertions.assertEquals (((WildcardQueryBuilder)query.must().get(0)).fieldName(), "lid"); - Assertions.assertEquals (((WildcardQueryBuilder)query.must().get(0)).value(), "*pdart14_meap"); + Assertions.assertTrue (query.must().get(0) instanceof SimpleQueryStringBuilder); + Assertions.assertTrue (((SimpleQueryStringBuilder)query.must().get(0)).fields().containsKey("lid")); + Assertions.assertEquals (((SimpleQueryStringBuilder)query.must().get(0)).value(), "*pdart14_meap"); } @@ -77,9 +77,9 @@ public void testNotLikeWildchar() Assertions.assertEquals(query.must().size(), 0); Assertions.assertEquals(query.mustNot().size(), 1); Assertions.assertEquals(query.should().size(), 0); - Assertions.assertTrue(query.mustNot().get(0) instanceof WildcardQueryBuilder); - Assertions.assertEquals(((WildcardQueryBuilder) query.mustNot().get(0)).fieldName(), "lid"); - Assertions.assertEquals(((WildcardQueryBuilder) query.mustNot().get(0)).value(), "pdart14_meap?"); + Assertions.assertTrue(query.mustNot().get(0) instanceof SimpleQueryStringBuilder); + Assertions.assertTrue(((SimpleQueryStringBuilder) query.mustNot().get(0)).fields().containsKey("lid")); + Assertions.assertEquals(((SimpleQueryStringBuilder) query.mustNot().get(0)).value(), "pdart14_meap?"); } @@ -92,9 +92,9 @@ public void testEscape() Assertions.assertEquals (query.must().size(), 1); Assertions.assertEquals (query.mustNot().size(), 0); Assertions.assertEquals (query.should().size(), 0); - Assertions.assertTrue (query.must().get(0) instanceof MatchQueryBuilder); - Assertions.assertEquals (((MatchQueryBuilder)query.must().get(0)).fieldName(), "lid"); - Assertions.assertEquals (((MatchQueryBuilder)query.must().get(0)).value(), "*pdart14_meap?"); + Assertions.assertTrue (query.must().get(0) instanceof TermQueryBuilder); + Assertions.assertEquals (((TermQueryBuilder)query.must().get(0)).fieldName(), "lid"); + Assertions.assertEquals (((TermQueryBuilder)query.must().get(0)).value(), "*pdart14_meap?"); } @@ -180,12 +180,12 @@ public void testNestedGrouping() Assertions.assertEquals (query.must().size(), 0); Assertions.assertEquals (query.mustNot().size(), 0); - Assertions.assertEquals (query.should().size(), 2); - Assertions.assertTrue (query.should().get(0) instanceof BoolQueryBuilder); - nest = (BoolQueryBuilder)query.should().get(0); + Assertions.assertEquals (query.filter().size(), 2); + Assertions.assertTrue (query.filter().get(0) instanceof BoolQueryBuilder); + nest = (BoolQueryBuilder)query.filter().get(0); Assertions.assertEquals (nest.must().size(), 2); Assertions.assertEquals (nest.mustNot().size(), 0); - Assertions.assertEquals (nest.should().size(), 0); + Assertions.assertEquals (nest.filter().size(), 0); Assertions.assertTrue (nest.must().get(0) instanceof RangeQueryBuilder); Assertions.assertTrue (nest.must().get(1) instanceof RangeQueryBuilder); Assertions.assertEquals (((RangeQueryBuilder)nest.must().get(0)).fieldName(), "timestamp"); @@ -198,10 +198,10 @@ public void testNestedGrouping() Assertions.assertEquals (((RangeQueryBuilder)nest.must().get(1)).to(), "27"); Assertions.assertTrue (((RangeQueryBuilder)nest.must().get(1)).includeLower()); Assertions.assertTrue (((RangeQueryBuilder)nest.must().get(1)).includeUpper()); - nest = (BoolQueryBuilder)query.should().get(1); + nest = (BoolQueryBuilder)query.filter().get(1); Assertions.assertEquals (nest.must().size(), 2); Assertions.assertEquals (nest.mustNot().size(), 0); - Assertions.assertEquals (nest.should().size(), 0); + Assertions.assertEquals (nest.filter().size(), 0); Assertions.assertTrue (nest.must().get(0) instanceof RangeQueryBuilder); Assertions.assertTrue (nest.must().get(1) instanceof RangeQueryBuilder); Assertions.assertEquals (((RangeQueryBuilder)nest.must().get(0)).fieldName(), "timestamp"); @@ -226,9 +226,9 @@ public void testNoWildcardQuoted() Assertions.assertEquals (query.must().size(), 1); Assertions.assertEquals (query.mustNot().size(), 0); Assertions.assertEquals (query.should().size(), 0); - Assertions.assertTrue (query.must().get(0) instanceof MatchQueryBuilder); - Assertions.assertEquals (((MatchQueryBuilder)query.must().get(0)).fieldName(), "ref_lid_target"); - Assertions.assertEquals (((MatchQueryBuilder)query.must().get(0)).value(), "urn:nasa:pds:context:target:planet.mercury"); + Assertions.assertTrue (query.must().get(0) instanceof TermQueryBuilder); + Assertions.assertEquals (((TermQueryBuilder)query.must().get(0)).fieldName(), "ref_lid_target"); + Assertions.assertEquals (((TermQueryBuilder)query.must().get(0)).value(), "urn:nasa:pds:context:target:planet.mercury"); } @Test