Skip to content

Commit 5bfa8cf

Browse files
committed
fixed tests
1 parent a0127c4 commit 5bfa8cf

File tree

5 files changed

+707
-11
lines changed

5 files changed

+707
-11
lines changed

server/src/main/java/org/elasticsearch/lucene/queries/TimestampIterator.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ public int advance(int target) throws IOException {
9999
case YES:
100100
return doc = target;
101101
case MAYBE:
102+
if (target > innerApproximation.docID()) {
103+
target = innerApproximation.advance(target);
104+
}
105+
if (target <= upTo) {
106+
return doc = target;
107+
}
108+
break;
102109
case NO:
103110
if (match == Match.NO) {
104111
primaryFieldSkipper.advance(target);

server/src/main/java/org/elasticsearch/lucene/queries/TimestampQuery.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,20 @@ public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float bo
6161

6262
@Override
6363
public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException {
64-
int maxDoc = context.reader().maxDoc();
65-
var timestampSkipper = context.reader().getDocValuesSkipper(FIELD_NAME);
64+
var reader = context.reader();
65+
int maxDoc = reader.maxDoc();
66+
if (maxDoc == 0) {
67+
return null;
68+
}
69+
if (reader.getFieldInfos().fieldInfo(FIELD_NAME) == null) {
70+
return null;
71+
}
72+
73+
Sort indexSort = reader.getMetaData().sort();
74+
assert indexSort != null;
75+
assert indexSort.getSort().length == 1 || indexSort.getSort().length == 2;
76+
77+
var timestampSkipper = reader.getDocValuesSkipper(FIELD_NAME);
6678
assert timestampSkipper != null;
6779
if (timestampSkipper.minValue() > maxTimestamp || timestampSkipper.maxValue() < minTimestamp) {
6880
return null;
@@ -71,14 +83,10 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti
7183
return ConstantScoreScorerSupplier.matchAll(score(), scoreMode, maxDoc);
7284
}
7385

74-
Sort indexSort = context.reader().getMetaData().sort();
75-
assert indexSort != null;
76-
assert indexSort.getSort().length == 1 || indexSort.getSort().length == 2;
77-
String primarySortField = indexSort.getSort()[0].getField();
78-
7986
var timestamps = getNumericDocValues(context);
87+
String primarySortField = indexSort.getSort()[0].getField();
8088
boolean timestampIsPrimarySort = primarySortField.equals(FIELD_NAME);
81-
var primaryFieldValues = timestampIsPrimarySort ? null : context.reader().getSortedDocValues(primarySortField);
89+
var primaryFieldValues = timestampIsPrimarySort ? null : reader.getSortedDocValues(primarySortField);
8290
if (primaryFieldValues == null || primaryFieldValues.getValueCount() <= 1) {
8391
var iterator = getIteratorIfTimestampIfPrimarySort(maxDoc, timestamps, timestampSkipper, minTimestamp, maxTimestamp);
8492
return ConstantScoreScorerSupplier.fromIterator(iterator, score(), scoreMode, maxDoc);
@@ -95,7 +103,7 @@ public float matchCost() {
95103
return 2; // 2 comparisons
96104
}
97105
};
98-
var primaryFieldSkipper = context.reader().getDocValuesSkipper(primarySortField);
106+
var primaryFieldSkipper = reader.getDocValuesSkipper(primarySortField);
99107
iterator = new TimestampIterator(iterator, timestampSkipper, primaryFieldSkipper, minTimestamp, maxTimestamp);
100108
return ConstantScoreScorerSupplier.fromIterator(TwoPhaseIterator.asDocIdSetIterator(iterator), score(), scoreMode, maxDoc);
101109
}
@@ -143,7 +151,7 @@ static NumericDocValues getNumericDocValues(LeafReaderContext ctx) throws IOExce
143151
var timestampValues = DocValues.getSortedNumeric(ctx.reader(), FIELD_NAME);
144152
assert timestampValues != null;
145153
var timestampSingleton = DocValues.unwrapSingleton(timestampValues);
146-
assert timestampSingleton != null;
154+
assert timestampSingleton != null : "@timestamp has multiple values per document";
147155
return timestampSingleton;
148156
}
149157

server/src/test/java/org/elasticsearch/index/mapper/DoubleIndexingDocTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
import org.apache.lucene.search.IndexSearcher;
1212
import org.apache.lucene.search.TopDocs;
13+
import org.elasticsearch.index.IndexVersion;
1314
import org.elasticsearch.index.query.SearchExecutionContext;
1415

1516
import static org.hamcrest.Matchers.equalTo;
1617
import static org.mockito.Mockito.mock;
18+
import static org.mockito.Mockito.when;
1719

1820
public class DoubleIndexingDocTests extends MapperServiceTestCase {
1921
public void testDoubleIndexingSameDoc() throws Exception {
@@ -31,6 +33,7 @@ public void testDoubleIndexingSameDoc() throws Exception {
3133
merge(mapperService, dynamicMapping(doc.dynamicMappingsUpdate()));
3234

3335
SearchExecutionContext context = mock(SearchExecutionContext.class);
36+
when(context.getIndexSettings()).thenReturn(createIndexSettings(IndexVersion.current(), getIndexSettings()));
3437

3538
withLuceneIndex(mapperService, iw -> {
3639
iw.addDocument(doc.rootDoc());

0 commit comments

Comments
 (0)