Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Vacha Shah <[email protected]>
  • Loading branch information
VachaShah committed Jan 21, 2024
1 parent 2f4273b commit 1a59c1b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ final class DefaultSearchContext extends SearchContext {
// SearchContexts use a BigArrays that can circuit break
this.bigArrays = bigArrays.withCircuitBreaking();
this.dfsResult = new DfsSearchResult(readerContext.id(), shardTarget, request);
this.queryResult = new QuerySearchResult(readerContext.id(), shardTarget, request, clusterService.getSettings());
this.queryResult = new QuerySearchResult(readerContext.id(), shardTarget, request);
this.fetchResult = new FetchSearchResult(readerContext.id(), shardTarget);
this.indexService = readerContext.indexService();
this.indexShard = readerContext.indexShard();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@

package org.opensearch.search.fetch;

import com.google.protobuf.ByteString;
import org.apache.lucene.search.TotalHits.Relation;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.core.common.bytes.BytesReference;
import org.opensearch.common.util.FeatureFlags;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.search.SearchHit;
Expand Down Expand Up @@ -105,7 +104,7 @@ public FetchSearchResult fetchResult() {
public void hits(SearchHits hits) {
assert assertNoSearchTarget(hits);
this.hits = hits;
if (this.fetchSearchResultProto != null) {
if (FeatureFlags.isEnabled(FeatureFlags.PROTOBUF_SETTING) && this.fetchSearchResultProto != null) {
QuerySearchResultProto.TotalHits.Builder totalHitsBuilder = QuerySearchResultProto.TotalHits.newBuilder();
totalHitsBuilder.setValue(hits.getTotalHits().value);
totalHitsBuilder.setRelation(
Expand All @@ -116,17 +115,6 @@ public void hits(SearchHits hits) {
FetchSearchResultProto.SearchHits.Builder searchHitsBuilder = FetchSearchResultProto.SearchHits.newBuilder();
searchHitsBuilder.setMaxScore(hits.getMaxScore());
searchHitsBuilder.setTotalHits(totalHitsBuilder.build());
for (SearchHit hit : hits.getHits()) {
FetchSearchResultProto.SearchHit.Builder searchHitBuilder = FetchSearchResultProto.SearchHit.newBuilder();
searchHitBuilder.setIndex(hit.getIndex());
searchHitBuilder.setId(hit.getId());
searchHitBuilder.setScore(hit.getScore());
searchHitBuilder.setSeqNo(hit.getSeqNo());
searchHitBuilder.setPrimaryTerm(hit.getPrimaryTerm());
searchHitBuilder.setVersion(hit.getVersion());
searchHitBuilder.setSource(ByteString.copyFrom(BytesReference.toBytes(hit.getSourceRef())));
searchHitsBuilder.addHits(searchHitBuilder.build());
}
this.fetchSearchResultProto = this.fetchSearchResultProto.toBuilder().setHits(searchHitsBuilder.build()).build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.io.stream.DelayableWriteable;
import org.opensearch.common.lucene.search.TopDocsAndMaxScore;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.FeatureFlags;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -119,12 +118,7 @@ public QuerySearchResult(byte[] in) throws IOException {
isNull = false;
}

public QuerySearchResult(
ShardSearchContextId contextId,
SearchShardTarget shardTarget,
ShardSearchRequest shardSearchRequest,
Settings settings
) {
public QuerySearchResult(ShardSearchContextId contextId, SearchShardTarget shardTarget, ShardSearchRequest shardSearchRequest) {
this.contextId = contextId;
setSearchShardTarget(shardTarget);
isNull = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.apache.lucene.tests.store.MockDirectoryWrapper;
import org.opensearch.action.OriginalIndices;
import org.opensearch.common.lucene.search.TopDocsAndMaxScore;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.AtomicArray;
import org.opensearch.common.util.concurrent.OpenSearchExecutors;
import org.opensearch.core.common.breaker.CircuitBreaker;
Expand Down Expand Up @@ -102,8 +101,7 @@ public void sendExecuteQuery(
QuerySearchResult queryResult = new QuerySearchResult(
new ShardSearchContextId("", 123),
new SearchShardTarget("node1", new ShardId("test", "na", 0), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
queryResult.topDocs(
new TopDocsAndMaxScore(
Expand All @@ -118,8 +116,7 @@ public void sendExecuteQuery(
QuerySearchResult queryResult = new QuerySearchResult(
new ShardSearchContextId("", 123),
new SearchShardTarget("node2", new ShardId("test", "na", 0), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
queryResult.topDocs(
new TopDocsAndMaxScore(
Expand Down Expand Up @@ -202,8 +199,7 @@ public void sendExecuteQuery(
QuerySearchResult queryResult = new QuerySearchResult(
new ShardSearchContextId("", 123),
new SearchShardTarget("node1", new ShardId("test", "na", 0), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
queryResult.topDocs(
new TopDocsAndMaxScore(
Expand Down Expand Up @@ -290,8 +286,7 @@ public void sendExecuteQuery(
QuerySearchResult queryResult = new QuerySearchResult(
new ShardSearchContextId("", 123),
new SearchShardTarget("node1", new ShardId("test", "na", 0), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
queryResult.topDocs(
new TopDocsAndMaxScore(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.opensearch.action.OriginalIndices;
import org.opensearch.common.UUIDs;
import org.opensearch.common.lucene.search.TopDocsAndMaxScore;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.OpenSearchExecutors;
import org.opensearch.core.common.breaker.CircuitBreaker;
import org.opensearch.core.common.breaker.NoopCircuitBreaker;
Expand Down Expand Up @@ -141,8 +140,7 @@ public void testFetchTwoDocument() {
QuerySearchResult queryResult = new QuerySearchResult(
ctx1,
new SearchShardTarget("node1", new ShardId("test", "na", 0), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
queryResult.topDocs(
new TopDocsAndMaxScore(
Expand All @@ -159,8 +157,7 @@ public void testFetchTwoDocument() {
queryResult = new QuerySearchResult(
ctx2,
new SearchShardTarget("node2", new ShardId("test", "na", 1), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
queryResult.topDocs(
new TopDocsAndMaxScore(
Expand Down Expand Up @@ -239,8 +236,7 @@ public void testFailFetchOneDoc() {
QuerySearchResult queryResult = new QuerySearchResult(
ctx,
new SearchShardTarget("node1", new ShardId("test", "na", 0), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
queryResult.topDocs(
new TopDocsAndMaxScore(
Expand All @@ -256,8 +252,7 @@ public void testFailFetchOneDoc() {
queryResult = new QuerySearchResult(
new ShardSearchContextId("", 321),
new SearchShardTarget("node2", new ShardId("test", "na", 1), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
queryResult.topDocs(
new TopDocsAndMaxScore(
Expand Down Expand Up @@ -338,8 +333,7 @@ public void testFetchDocsConcurrently() throws InterruptedException {
QuerySearchResult queryResult = new QuerySearchResult(
new ShardSearchContextId("", i),
new SearchShardTarget("node1", new ShardId("test", "na", 0), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
queryResult.topDocs(
new TopDocsAndMaxScore(
Expand Down Expand Up @@ -429,8 +423,7 @@ public void testExceptionFailsPhase() {
QuerySearchResult queryResult = new QuerySearchResult(
new ShardSearchContextId("", 123),
new SearchShardTarget("node1", new ShardId("test", "na", 0), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
queryResult.topDocs(
new TopDocsAndMaxScore(
Expand All @@ -446,8 +439,7 @@ public void testExceptionFailsPhase() {
queryResult = new QuerySearchResult(
new ShardSearchContextId("", 321),
new SearchShardTarget("node2", new ShardId("test", "na", 1), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
queryResult.topDocs(
new TopDocsAndMaxScore(
Expand Down Expand Up @@ -524,8 +516,7 @@ public void testCleanupIrrelevantContexts() { // contexts that are not fetched s
QuerySearchResult queryResult = new QuerySearchResult(
ctx1,
new SearchShardTarget("node1", new ShardId("test", "na", 0), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
queryResult.topDocs(
new TopDocsAndMaxScore(
Expand All @@ -542,8 +533,7 @@ public void testCleanupIrrelevantContexts() { // contexts that are not fetched s
queryResult = new QuerySearchResult(
ctx2,
new SearchShardTarget("node2", new ShardId("test", "na", 1), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
queryResult.topDocs(
new TopDocsAndMaxScore(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,7 @@ private static AtomicArray<SearchPhaseResult> generateQueryResults(
clusterAlias,
OriginalIndices.NONE
);
QuerySearchResult querySearchResult = new QuerySearchResult(
new ShardSearchContextId("", shardIndex),
searchShardTarget,
null,
Settings.EMPTY
);
QuerySearchResult querySearchResult = new QuerySearchResult(new ShardSearchContextId("", shardIndex), searchShardTarget, null);
final TopDocs topDocs;
float maxScore = 0;
if (searchHitsSize == 0) {
Expand Down Expand Up @@ -690,8 +685,7 @@ private void consumerTestCase(int numEmptyResponses) throws Exception {
QuerySearchResult result = new QuerySearchResult(
new ShardSearchContextId("", 0),
new SearchShardTarget("node", new ShardId("a", "b", 0), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
result.topDocs(
new TopDocsAndMaxScore(new TopDocs(new TotalHits(0, TotalHits.Relation.EQUAL_TO), new ScoreDoc[0]), Float.NaN),
Expand All @@ -705,8 +699,7 @@ private void consumerTestCase(int numEmptyResponses) throws Exception {
result = new QuerySearchResult(
new ShardSearchContextId("", 1),
new SearchShardTarget("node", new ShardId("a", "b", 0), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
result.topDocs(
new TopDocsAndMaxScore(new TopDocs(new TotalHits(0, TotalHits.Relation.EQUAL_TO), new ScoreDoc[0]), Float.NaN),
Expand All @@ -720,8 +713,7 @@ private void consumerTestCase(int numEmptyResponses) throws Exception {
result = new QuerySearchResult(
new ShardSearchContextId("", 1),
new SearchShardTarget("node", new ShardId("a", "b", 0), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
result.topDocs(
new TopDocsAndMaxScore(new TopDocs(new TotalHits(0, TotalHits.Relation.EQUAL_TO), new ScoreDoc[0]), Float.NaN),
Expand Down Expand Up @@ -797,8 +789,7 @@ public void testConsumerConcurrently() throws Exception {
QuerySearchResult result = new QuerySearchResult(
new ShardSearchContextId("", id),
new SearchShardTarget("node", new ShardId("a", "b", id), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
result.topDocs(
new TopDocsAndMaxScore(
Expand Down Expand Up @@ -859,8 +850,7 @@ public void testConsumerOnlyAggs() throws Exception {
QuerySearchResult result = new QuerySearchResult(
new ShardSearchContextId("", i),
new SearchShardTarget("node", new ShardId("a", "b", i), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
result.topDocs(
new TopDocsAndMaxScore(new TopDocs(new TotalHits(1, TotalHits.Relation.EQUAL_TO), new ScoreDoc[0]), number),
Expand Down Expand Up @@ -913,8 +903,7 @@ public void testConsumerOnlyHits() throws Exception {
QuerySearchResult result = new QuerySearchResult(
new ShardSearchContextId("", i),
new SearchShardTarget("node", new ShardId("a", "b", i), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
result.topDocs(
new TopDocsAndMaxScore(
Expand Down Expand Up @@ -970,8 +959,7 @@ public void testReduceTopNWithFromOffset() throws Exception {
QuerySearchResult result = new QuerySearchResult(
new ShardSearchContextId("", i),
new SearchShardTarget("node", new ShardId("a", "b", i), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
ScoreDoc[] docs = new ScoreDoc[3];
for (int j = 0; j < docs.length; j++) {
Expand Down Expand Up @@ -1026,8 +1014,7 @@ public void testConsumerSortByField() throws Exception {
QuerySearchResult result = new QuerySearchResult(
new ShardSearchContextId("", i),
new SearchShardTarget("node", new ShardId("a", "b", i), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
result.topDocs(new TopDocsAndMaxScore(topDocs, Float.NaN), docValueFormats);
result.setShardIndex(i);
Expand Down Expand Up @@ -1076,8 +1063,7 @@ public void testConsumerFieldCollapsing() throws Exception {
QuerySearchResult result = new QuerySearchResult(
new ShardSearchContextId("", i),
new SearchShardTarget("node", new ShardId("a", "b", i), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
result.topDocs(new TopDocsAndMaxScore(topDocs, Float.NaN), docValueFormats);
result.setShardIndex(i);
Expand Down Expand Up @@ -1121,8 +1107,7 @@ public void testConsumerSuggestions() throws Exception {
QuerySearchResult result = new QuerySearchResult(
new ShardSearchContextId("", i),
new SearchShardTarget("node", new ShardId("a", "b", i), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
List<Suggest.Suggestion<? extends Suggest.Suggestion.Entry<? extends Suggest.Suggestion.Entry.Option>>> suggestions =
new ArrayList<>();
Expand Down Expand Up @@ -1263,8 +1248,7 @@ public void onFinalReduce(List<SearchShard> shards, TotalHits totalHits, Interna
QuerySearchResult result = new QuerySearchResult(
new ShardSearchContextId("", id),
new SearchShardTarget("node", new ShardId("a", "b", id), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
result.topDocs(
new TopDocsAndMaxScore(
Expand Down Expand Up @@ -1350,8 +1334,7 @@ private void testReduceCase(boolean shouldFail) throws Exception {
QuerySearchResult result = new QuerySearchResult(
new ShardSearchContextId(UUIDs.randomBase64UUID(), index),
new SearchShardTarget("node", new ShardId("a", "b", index), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
result.topDocs(
new TopDocsAndMaxScore(new TopDocs(new TotalHits(0, TotalHits.Relation.EQUAL_TO), Lucene.EMPTY_SCORE_DOCS), Float.NaN),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.routing.GroupShardsIterator;
import org.opensearch.common.lucene.search.TopDocsAndMaxScore;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.concurrent.OpenSearchExecutors;
import org.opensearch.core.common.Strings;
Expand Down Expand Up @@ -127,8 +126,7 @@ public void sendExecuteQuery(
QuerySearchResult queryResult = new QuerySearchResult(
new ShardSearchContextId("N/A", 123),
new SearchShardTarget("node1", new ShardId("idx", "na", shardId), null, OriginalIndices.NONE),
null,
Settings.EMPTY
null
);
SortField sortField = new SortField("timestamp", SortField.Type.LONG);
if (withCollapse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ private static QuerySearchResult createTestInstance() throws Exception {
QuerySearchResult result = new QuerySearchResult(
new ShardSearchContextId(UUIDs.base64UUID(), randomLong()),
new SearchShardTarget("node", shardId, null, OriginalIndices.NONE),
shardSearchRequest,
Settings.EMPTY
shardSearchRequest
);
if (randomBoolean()) {
result.terminatedEarly(randomBoolean());
Expand Down

0 comments on commit 1a59c1b

Please sign in to comment.