Skip to content

Commit bf35e4b

Browse files
committed
Add unit test & address comments
Signed-off-by: sjs004 <simarjeet.singh004@gmail.com>
1 parent f9c5939 commit bf35e4b

File tree

3 files changed

+42
-32
lines changed

3 files changed

+42
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4747
- Fix file-based ingestion consumer to handle start point beyond max line number([#19757])(https://github.com/opensearch-project/OpenSearch/pull/19757))
4848
- Fix IndexOutOfBoundsException when running include/exclude on non-existent prefix in terms aggregations ([#19637](https://github.com/opensearch-project/OpenSearch/pull/19637))
4949
- Fixed assertion unsafe use of ClusterService.state() in ResourceUsageCollectorService ([#19775])(https://github.com/opensearch-project/OpenSearch/pull/19775))
50-
- Add S3Repository.LEGACY_MD5_CHECKSUM_CALCULATION to list of repository-s3 settings ([#19788](https://github.com/opensearch-project/OpenSearch/pull/19788))
51-
- Fix unnecessary refreshes on update preparation failures ([#15261](https://github.com/opensearch-project/OpenSearch/issues/15261))
52-
- Fix NullPointerException in segment replicator ([#18997](https://github.com/opensearch-project/OpenSearch/pull/18997))
53-
- Ensure that plugins that utilize dumpCoverage can write to jacoco.dir when tests.security.manager is enabled ([#18983](https://github.com/opensearch-project/OpenSearch/pull/18983))
54-
- Fix OOM due to large number of shard result buffering ([#19066](https://github.com/opensearch-project/OpenSearch/pull/19066))
55-
- Fix flaky tests in CloseIndexIT by addressing cluster state synchronization issues ([#18878](https://github.com/opensearch-project/OpenSearch/issues/18878))
56-
- [Tiered Caching] Handle query execution exception ([#19000](https://github.com/opensearch-project/OpenSearch/issues/19000))
57-
- Grant access to testclusters dir for tests ([#19085](https://github.com/opensearch-project/OpenSearch/issues/19085))
58-
- Fix assertion error when collapsing search results with concurrent segment search enabled ([#19053](https://github.com/opensearch-project/OpenSearch/pull/19053))
59-
- Fix skip_unavailable setting changing to default during node drop issue ([#18766](https://github.com/opensearch-project/OpenSearch/pull/18766))
60-
- Fix issue with s3-compatible repositories due to missing checksum trailing headers ([#19220](https://github.com/opensearch-project/OpenSearch/pull/19220))
61-
- Add reference count control in NRTReplicationEngine#acquireLastIndexCommit ([#19214](https://github.com/opensearch-project/OpenSearch/pull/19214))
62-
- Fix pull-based ingestion pause state initialization during replica promotion ([#19212](https://github.com/opensearch-project/OpenSearch/pull/19212))
63-
- Fix QueryPhaseResultConsumer incomplete callback loops ([#19231](https://github.com/opensearch-project/OpenSearch/pull/19231))
64-
- Fix the `scaled_float` precision issue ([#19188](https://github.com/opensearch-project/OpenSearch/pull/19188))
65-
- Fix Using an excessively large reindex slice can lead to a JVM OutOfMemoryError on coordinator.([#18964](https://github.com/opensearch-project/OpenSearch/pull/18964))
66-
- Add alias write index policy to control writeIndex during restore([#1511](https://github.com/opensearch-project/OpenSearch/pull/19368))
67-
- [Flaky Test] Fix flaky test in SecureReactorNetty4HttpServerTransportTests with reproducible seed ([#19327](https://github.com/opensearch-project/OpenSearch/pull/19327))
68-
- Remove unnecessary looping in field data cache clear ([#19116](https://github.com/opensearch-project/OpenSearch/pull/19116))
69-
- [Flaky Test] Fix flaky test IngestFromKinesisIT.testAllActiveIngestion ([#19380](https://github.com/opensearch-project/OpenSearch/pull/19380))
70-
- Fix lag metric for pull-based ingestion when streaming source is empty ([#19393](https://github.com/opensearch-project/OpenSearch/pull/19393))
71-
- Fix IntervalQuery flaky test ([#19332](https://github.com/opensearch-project/OpenSearch/pull/19332))
72-
- Fix ingestion state xcontent serialization in IndexMetadata and fail fast on mapping errors([#19320](https://github.com/opensearch-project/OpenSearch/pull/19320))
73-
- Fix updated keyword field params leading to stale responses from request cache ([#19385](https://github.com/opensearch-project/OpenSearch/pull/19385))
74-
- Fix cardinality agg pruning optimization by self collecting ([#19473](https://github.com/opensearch-project/OpenSearch/pull/19473))
75-
- Implement SslHandler retrieval logic for transport-reactor-netty4 plugin ([#19458](https://github.com/opensearch-project/OpenSearch/pull/19458))
76-
- Cache serialised cluster state based on cluster state version and node version.([#19307](https://github.com/opensearch-project/OpenSearch/pull/19307))
77-
- Handle negative search request nodes stats ([#19340](https://github.com/opensearch-project/OpenSearch/pull/19340))
7850
- Fix Unified highlighter for nested fields when using matchPhrasePrefixQuery ([#19442](https://github.com/opensearch-project/OpenSearch/pull/19442))
51+
- Add S3Repository.LEGACY_MD5_CHECKSUM_CALCULATION to list of repository-s3 settings ([#19788](https://github.com/opensearch-project/OpenSearch/pull/19788))
7952

8053
### Dependencies
8154
- Update to Gradle 9.1 ([#19575](https://github.com/opensearch-project/OpenSearch/pull/19575))

server/src/main/java/org/opensearch/lucene/search/uhighlight/CustomUnifiedHighlighter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ protected Collection<Query> preSpanQueryRewrite(Query query) {
229229
* Translate custom queries in queries that are supported by the unified highlighter.
230230
*/
231231
private Collection<Query> rewriteCustomQuery(Query query) {
232-
if (query instanceof MultiPhrasePrefixQuery) {
233-
MultiPhrasePrefixQuery mpq = (MultiPhrasePrefixQuery) query;
232+
if (query instanceof MultiPhrasePrefixQuery mpq) {
234233
Term[][] terms = mpq.getTerms();
235234
int[] positions = mpq.getPositions();
236235
SpanQuery[] positionSpanQueries = new SpanQuery[positions.length];
@@ -263,13 +262,14 @@ private Collection<Query> rewriteCustomQuery(Query query) {
263262
// if original slop is 0 then require inOrder
264263
boolean inorder = (mpq.getSlop() == 0);
265264
return Collections.singletonList(new SpanNearQuery(positionSpanQueries, mpq.getSlop() + positionGaps, inorder));
266-
} else if (query instanceof OpenSearchToParentBlockJoinQuery) {
267-
return Collections.singletonList(((OpenSearchToParentBlockJoinQuery) query).getChildQuery());
265+
} else if (query instanceof OpenSearchToParentBlockJoinQuery parentQuery) {
266+
return Collections.singletonList(parentQuery.getChildQuery());
268267
} else {
269268
return null;
270269
}
271270
}
272271

272+
273273
/**
274274
* Forces the offset source for this highlighter
275275
*/

server/src/test/java/org/opensearch/lucene/search/uhighlight/CustomUnifiedHighlighterTests.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.apache.lucene.index.IndexOptions;
4545
import org.apache.lucene.index.IndexWriterConfig;
4646
import org.apache.lucene.index.Term;
47+
import org.apache.lucene.index.LeafReaderContext;
4748
import org.apache.lucene.queries.CommonTermsQuery;
4849
import org.apache.lucene.search.BooleanClause;
4950
import org.apache.lucene.search.BooleanQuery;
@@ -56,13 +57,19 @@
5657
import org.apache.lucene.search.TermQuery;
5758
import org.apache.lucene.search.TopDocs;
5859
import org.apache.lucene.search.highlight.DefaultEncoder;
60+
import org.apache.lucene.search.join.BitSetProducer;
61+
import org.apache.lucene.search.join.ScoreMode;
5962
import org.apache.lucene.search.uhighlight.UnifiedHighlighter;
6063
import org.apache.lucene.store.Directory;
6164
import org.apache.lucene.tests.index.RandomIndexWriter;
65+
import org.apache.lucene.util.BitSet;
66+
import org.apache.lucene.util.FixedBitSet;
6267
import org.opensearch.common.lucene.search.MultiPhrasePrefixQuery;
6368
import org.opensearch.core.common.Strings;
69+
import org.opensearch.index.search.OpenSearchToParentBlockJoinQuery;
6470
import org.opensearch.test.OpenSearchTestCase;
6571

72+
import java.io.IOException;
6673
import java.text.BreakIterator;
6774
import java.util.Locale;
6875

@@ -335,4 +342,34 @@ public void testOverlappingTerms() throws Exception {
335342
assertHighlightOneDoc("text", inputs, analyzer, query, Locale.ROOT, BreakIterator.getSentenceInstance(Locale.ROOT), 0, outputs);
336343
}
337344

345+
public void testOpenSearchToParentBlockJoinQuery() throws Exception {
346+
final String[] inputs = { "Nested highlighting query." };
347+
final String[] outputs = { "Nested <b>highlighting</b> query." };
348+
349+
Query childQuery = new TermQuery(new Term("text", "highlighting"));
350+
BitSetProducer parentsFilter = new BitSetProducer() {
351+
@Override
352+
public BitSet getBitSet(LeafReaderContext context) throws IOException {
353+
FixedBitSet bits = new FixedBitSet(context.reader().maxDoc());
354+
for (int i = 0; i < context.reader().maxDoc(); i++) {
355+
bits.set(i);
356+
}
357+
return bits;
358+
}
359+
};
360+
361+
Query parentQuery = new OpenSearchToParentBlockJoinQuery(childQuery, parentsFilter, ScoreMode.None, "foo");
362+
assertHighlightOneDoc(
363+
"text",
364+
inputs,
365+
new StandardAnalyzer(),
366+
parentQuery,
367+
Locale.ROOT,
368+
BreakIterator.getSentenceInstance(Locale.ROOT),
369+
0,
370+
outputs
371+
);
372+
}
373+
374+
338375
}

0 commit comments

Comments
 (0)