Skip to content

Commit

Permalink
Merge branch 'main' into create-version-2
Browse files Browse the repository at this point in the history
Signed-off-by: Anshu Agarwal <[email protected]>
  • Loading branch information
Anshu Agarwal committed Sep 4, 2024
2 parents 253abcc + 4f57d6a commit 7529554
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix split response processor not included in allowlist ([#15393](https://github.com/opensearch-project/OpenSearch/pull/15393))
- Fix unchecked cast in dynamic action map getter ([#15394](https://github.com/opensearch-project/OpenSearch/pull/15394))
- Fix null values indexed as "null" strings in flat_object field ([#14069](https://github.com/opensearch-project/OpenSearch/pull/14069))
- Fix terms query on wildcard field returns nothing ([#15607](https://github.com/opensearch-project/OpenSearch/pull/15607))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,13 @@ setup:
my_field:
value: ".*"
- match: { hits.total.value: 5 }
---
"terms query on wildcard field matches":
- do:
search:
index: test
body:
query:
terms: { my_field: ["AbCd"] }
- match: { hits.total.value: 1 }
- match: { hits.hits.0._id: "5" }
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower

@Override
public Query termQueryCaseInsensitive(Object value, QueryShardContext context) {
return wildcardQuery(value.toString(), MultiTermQuery.CONSTANT_SCORE_REWRITE, true, context);
return wildcardQuery(BytesRefs.toString(value), MultiTermQuery.CONSTANT_SCORE_REWRITE, true, context);
}

@Override
Expand All @@ -649,7 +649,7 @@ public Query termsQuery(List<?> values, QueryShardContext context) {
Set<String> expectedValues = new HashSet<>();
StringBuilder pattern = new StringBuilder();
for (Object value : values) {
String stringVal = value.toString();
String stringVal = BytesRefs.toString(value);
builder.add(matchAllTermsQuery(name(), getRequiredNGrams(stringVal)), BooleanClause.Occur.SHOULD);
expectedValues.add(stringVal);
if (pattern.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ public void grow(int count) {
public void visit(int docID) {
// it is possible that size < 1024 and docCount < size but we will continue to count through all the 1024 docs
// and collect less, but it won't hurt performance
if (docCount[0] < size) {
adder.add(docID);
docCount[0]++;
if (docCount[0] >= size) {
return;
}
adder.add(docID);
docCount[0]++;
}

@Override
Expand Down Expand Up @@ -231,7 +232,7 @@ private void intersectRight(PointValues.PointTree pointTree, PointValues.Interse
public void intersectLeft(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree, long[] docCount)
throws IOException {
PointValues.Relation r = visitor.compare(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue());
if (docCount[0] > size) {
if (docCount[0] >= size) {
return;
}
switch (r) {
Expand Down Expand Up @@ -279,7 +280,7 @@ public void intersectLeft(PointValues.IntersectVisitor visitor, PointValues.Poin
public void intersectRight(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree, long[] docCount)
throws IOException {
PointValues.Relation r = visitor.compare(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue());
if (docCount[0] > size) {
if (docCount[0] >= size) {
return;
}
switch (r) {
Expand Down Expand Up @@ -435,6 +436,10 @@ public boolean canApproximate(SearchContext context) {
if (!(context.query() instanceof ApproximateIndexOrDocValuesQuery)) {
return false;
}
// size 0 could be set for caching
if (context.from() + context.size() == 0) {
this.setSize(10_000);
}
this.setSize(Math.max(context.from() + context.size(), context.trackTotalHitsUpTo()));
if (context.request() != null && context.request().source() != null) {
FieldSortBuilder primarySortField = FieldSortBuilder.getPrimaryFieldSortOrNull(context.request().source());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ public void testApproximateRangeWithSizeUnderDefault() throws IOException {
}
doc.add(new LongPoint("point", scratch));
iw.addDocument(doc);
if (i % 15 == 0) iw.flush();
}
iw.flush();
iw.forceMerge(1);
try (IndexReader reader = iw.getReader()) {
try {
long lower = 0;
Expand Down Expand Up @@ -168,6 +168,7 @@ public void testApproximateRangeWithSizeOverDefault() throws IOException {
iw.addDocument(doc);
}
iw.flush();
iw.forceMerge(1);
try (IndexReader reader = iw.getReader()) {
try {
long lower = 0;
Expand All @@ -185,7 +186,7 @@ protected String toString(int dimension, byte[] value) {
};
IndexSearcher searcher = new IndexSearcher(reader);
TopDocs topDocs = searcher.search(approximateQuery, 11000);
assertEquals(topDocs.totalHits, new TotalHits(11001, TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO));
assertEquals(topDocs.totalHits, new TotalHits(11000, TotalHits.Relation.EQUAL_TO));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -213,6 +214,7 @@ public void testApproximateRangeShortCircuit() throws IOException {
if (i % 10 == 0) iw.flush();
}
iw.flush();
iw.forceMerge(1);
try (IndexReader reader = iw.getReader()) {
try {
long lower = 0;
Expand Down Expand Up @@ -258,6 +260,7 @@ public void testApproximateRangeShortCircuitAscSort() throws IOException {
iw.addDocument(doc);
}
iw.flush();
iw.forceMerge(1);
try (IndexReader reader = iw.getReader()) {
try {
long lower = 0;
Expand All @@ -284,12 +287,12 @@ protected String toString(int dimension, byte[] value) {
assertNotEquals(topDocs.totalHits, topDocs1.totalHits);
assertEquals(topDocs.totalHits, new TotalHits(10, TotalHits.Relation.EQUAL_TO));
assertEquals(topDocs1.totalHits, new TotalHits(21, TotalHits.Relation.EQUAL_TO));
assertEquals(topDocs.scoreDocs[0].doc, 0);
assertEquals(topDocs.scoreDocs[1].doc, 1);
assertEquals(topDocs.scoreDocs[2].doc, 2);
assertEquals(topDocs.scoreDocs[3].doc, 3);
assertEquals(topDocs.scoreDocs[4].doc, 4);
assertEquals(topDocs.scoreDocs[5].doc, 5);
assertEquals(topDocs.scoreDocs[0].doc, topDocs1.scoreDocs[0].doc);
assertEquals(topDocs.scoreDocs[1].doc, topDocs1.scoreDocs[1].doc);
assertEquals(topDocs.scoreDocs[2].doc, topDocs1.scoreDocs[2].doc);
assertEquals(topDocs.scoreDocs[3].doc, topDocs1.scoreDocs[3].doc);
assertEquals(topDocs.scoreDocs[4].doc, topDocs1.scoreDocs[4].doc);
assertEquals(topDocs.scoreDocs[5].doc, topDocs1.scoreDocs[5].doc);

} catch (IOException e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit 7529554

Please sign in to comment.