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

issue 160: apply stash for issue 134 #161

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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()))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void setResponse (SearchHit hit, List<String> fields)
@SuppressWarnings("unchecked")
public int setResponse(HitIterator hits, Summary summary, List<String> fields, boolean onlySummary)
{
int count;
PdsProducts products = new PdsProducts();
Set<String> uniqueProperties = new TreeSet<String>();

Expand All @@ -72,13 +73,14 @@ public int setResponse(HitIterator hits, Summary summary, List<String> fields, b
products.getData().get(products.getData().size()-1).setProperties((Map<String, PropertyArrayValues>)(Map<String, ?>)ProductBusinessObject.getFilteredProperties(kvp, null, null));
}
}

count = products.getData().size();

if (onlySummary) products.setData(null);

summary.setProperties(new ArrayList<String>(uniqueProperties));
products.setSummary(summary);
this.products = products;
return products.getData().size();
return count;
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions service/src/main/resources/application.properties.all
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}


Expand All @@ -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?");
}


Expand All @@ -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?");
}


Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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
Expand Down