Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczi committed Dec 16, 2024
1 parent 44a5132 commit 71c4823
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
1 change: 0 additions & 1 deletion docs/reference/search/retriever.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ GET movies/_search
}
----
// TEST[skip:uses ELSER]

<1> Specifies the number of top documents to return in the final response.
<2> A `rescorer` retriever applied as the final step.
<3> The definition of the `query` rescorer.
Expand Down
1 change: 1 addition & 0 deletions rest-api-spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ tasks.named("yamlRestCompatTestTransform").configure ({ task ->
task.skipTest("search/520_fetch_fields/fetch _seq_no via fields", "error code is changed from 5xx to 400 in 9.0")
task.skipTest("search.vectors/41_knn_search_bbq_hnsw/Test knn search", "Scoring has changed in latest versions")
task.skipTest("search.vectors/42_knn_search_bbq_flat/Test knn search", "Scoring has changed in latest versions")
task.skipTest("search/90_search_after/_shard_doc sort", "restriction has been lifted in latest versions")
})
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.store.Directory;
import org.apache.lucene.tests.index.RandomIndexWriter;
import org.apache.lucene.tests.store.BaseDirectoryWrapper;
Expand Down Expand Up @@ -245,7 +246,10 @@ protected Engine.Searcher acquireSearcherInternal(String source) {
// resultWindow not greater than maxResultWindow and both rescore and sort are not null
context1.from(0);
DocValueFormat docValueFormat = mock(DocValueFormat.class);
SortAndFormats sortAndFormats = new SortAndFormats(new Sort(), new DocValueFormat[] { docValueFormat });
SortAndFormats sortAndFormats = new SortAndFormats(
new Sort(new SortField[] { SortField.FIELD_DOC }),
new DocValueFormat[] { docValueFormat }
);
context1.sort(sortAndFormats);

RescoreContext rescoreContext = mock(RescoreContext.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,36 @@
import org.elasticsearch.usage.SearchUsage;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentParser;
import org.junit.AfterClass;
import org.junit.BeforeClass;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.List;

import static java.util.Collections.emptyList;

public class RescorerRetrieverBuilderParsingTests extends AbstractXContentTestCase<RescorerRetrieverBuilder> {
private static List<NamedXContentRegistry.Entry> xContentRegistryEntries;

@BeforeClass
public static void init() {
xContentRegistryEntries = new SearchModule(Settings.EMPTY, emptyList()).getNamedXContents();
}

@AfterClass
public static void afterClass() throws Exception {
xContentRegistryEntries = null;
}

@Override
protected RescorerRetrieverBuilder createTestInstance() {
int num = randomIntBetween(1, 3);
List<RescorerBuilder<?>> rescorers = new ArrayList<>();
for (int i = 0; i < num; i++) {
rescorers.add(QueryRescorerBuilderTests.randomRescoreBuilder());
}
final RetrieverBuilder retriever;
if (randomBoolean()) {
retriever = KnnRetrieverBuilderParsingTests.createRandomKnnRetrieverBuilder();
} else {
retriever = StandardRetrieverBuilderParsingTests.createRandomStandardRetrieverBuilder((xContent, data) -> {
try {
return createParser(xContent, data);
} catch (IOException ioe) {
throw new UncheckedIOException(ioe);
}
});
}
return new RescorerRetrieverBuilder(retriever, rescorers);
return new RescorerRetrieverBuilder(TestRetrieverBuilder.createRandomTestRetrieverBuilder(), rescorers);
}

@Override
Expand All @@ -61,6 +64,15 @@ protected boolean supportsUnknownFields() {

@Override
protected NamedXContentRegistry xContentRegistry() {
return new NamedXContentRegistry(new SearchModule(Settings.EMPTY, List.of()).getNamedXContents());
List<NamedXContentRegistry.Entry> entries = new ArrayList<>(xContentRegistryEntries);
entries.add(
new NamedXContentRegistry.Entry(
RetrieverBuilder.class,
TestRetrieverBuilder.TEST_SPEC.getName(),
(p, c) -> TestRetrieverBuilder.TEST_SPEC.getParser().fromXContent(p, (RetrieverParserContext) c),
TestRetrieverBuilder.TEST_SPEC.getName().getForRestApiVersion()
)
);
return new NamedXContentRegistry(entries);
}
}

0 comments on commit 71c4823

Please sign in to comment.