Skip to content

Commit

Permalink
don't wrap index reader
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnvg committed Aug 23, 2023
1 parent 1c720de commit 51869c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.elasticsearch.index.fielddata;

import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.FieldDoc;
import org.apache.lucene.search.IndexSearcher;
Expand Down Expand Up @@ -60,6 +61,13 @@ protected long minRamBytesUsed() {
return 1;
}

protected IndexSearcher newIndexSearcher(IndexReader indexReader) {
// IndexReader can't randomly wrapped with these field data tests.
// Sometimes ParallelCompositeReader is used and its getCoreCacheHelper() method sometimes returns null,
// and IndicesFieldDataCache can't handle this.
return newSearcher(indexReader, false);
}

public void testDeletedDocs() throws Exception {
add2SingleValuedDocumentsAndDeleteOneOfThem();
IndexFieldData<?> indexFieldData = getForField("value");
Expand Down Expand Up @@ -99,7 +107,7 @@ public void testSingleValueAllSet() throws Exception {
assertValues(bytesValues, 1, one());
assertValues(bytesValues, 2, three());

IndexSearcher searcher = newSearcher(readerContext.reader());
IndexSearcher searcher = newIndexSearcher(readerContext.reader());
TopFieldDocs topDocs;
SortField sortField = indexFieldData.sortField(null, MultiValueMode.MIN, null, false);
topDocs = searcher.search(new MatchAllDocsQuery(), 10, new Sort(sortField));
Expand Down Expand Up @@ -179,7 +187,7 @@ public void testMultiValueAllSet() throws Exception {
assertValues(bytesValues, 1, one());
assertValues(bytesValues, 2, three());

IndexSearcher searcher = newSearcher(DirectoryReader.open(writer));
IndexSearcher searcher = newIndexSearcher(DirectoryReader.open(writer));
SortField sortField = indexFieldData.sortField(null, MultiValueMode.MIN, null, false);
TopFieldDocs topDocs = searcher.search(new MatchAllDocsQuery(), 10, new Sort(sortField));
assertThat(topDocs.totalHits.value, equalTo(3L));
Expand Down Expand Up @@ -244,7 +252,7 @@ public void testSortMultiValuesFields() throws Exception {
fillExtendedMvSet();
IndexFieldData<?> indexFieldData = getForField("value");

IndexSearcher searcher = newSearcher(DirectoryReader.open(writer));
IndexSearcher searcher = newIndexSearcher(DirectoryReader.open(writer));
SortField sortField = indexFieldData.sortField(null, MultiValueMode.MIN, null, false);
TopFieldDocs topDocs = searcher.search(new MatchAllDocsQuery(), 10, new Sort(sortField));
assertThat(topDocs.totalHits.value, equalTo(8L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public void testActualMissingValue(boolean reverse) throws IOException {

final IndexFieldData<?> indexFieldData = getForField("value");
final String missingValue = values[1];
IndexSearcher searcher = newSearcher(DirectoryReader.open(writer));
IndexSearcher searcher = newIndexSearcher(DirectoryReader.open(writer));
SortField sortField = indexFieldData.sortField(missingValue, MultiValueMode.MIN, null, reverse);
TopFieldDocs topDocs = searcher.search(
new MatchAllDocsQuery(),
Expand Down Expand Up @@ -312,7 +312,7 @@ public void testSortMissing(boolean first, boolean reverse) throws IOException {
}
}
final IndexFieldData<?> indexFieldData = getForField("value");
IndexSearcher searcher = newSearcher(DirectoryReader.open(writer));
IndexSearcher searcher = newIndexSearcher(DirectoryReader.open(writer));
SortField sortField = indexFieldData.sortField(first ? "_first" : "_last", MultiValueMode.MIN, null, reverse);
TopFieldDocs topDocs = searcher.search(
new MatchAllDocsQuery(),
Expand Down Expand Up @@ -387,7 +387,7 @@ public void testNestedSorting(MultiValueMode sortMode) throws IOException {
}
DirectoryReader directoryReader = DirectoryReader.open(writer);
directoryReader = ElasticsearchDirectoryReader.wrap(directoryReader, new ShardId(indexService.index(), 0));
IndexSearcher searcher = newSearcher(directoryReader);
IndexSearcher searcher = newIndexSearcher(directoryReader);
IndexFieldData<?> fieldData = getForField("text");
final Object missingValue = switch (randomInt(4)) {
case 0 -> "_first";
Expand Down

0 comments on commit 51869c8

Please sign in to comment.