|
36 | 36 | import org.apache.lucene.document.SortedNumericDocValuesField;
|
37 | 37 | import org.apache.lucene.document.StoredField;
|
38 | 38 | import org.apache.lucene.index.IndexReader;
|
| 39 | +import org.apache.lucene.index.LeafReader; |
39 | 40 | import org.apache.lucene.index.PointValues;
|
| 41 | +import org.apache.lucene.index.SortedNumericDocValues; |
40 | 42 | import org.apache.lucene.search.BoostQuery;
|
41 | 43 | import org.apache.lucene.search.IndexOrDocValuesQuery;
|
42 | 44 | import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery;
|
|
74 | 76 | import java.time.ZonedDateTime;
|
75 | 77 | import java.util.Arrays;
|
76 | 78 | import java.util.Collections;
|
| 79 | +import java.util.HashMap; |
77 | 80 | import java.util.List;
|
78 | 81 | import java.util.Locale;
|
79 | 82 | import java.util.Map;
|
@@ -330,7 +333,8 @@ public DateFieldMapper build(BuilderContext context) {
|
330 | 333 | buildFormatter(),
|
331 | 334 | resolution,
|
332 | 335 | nullValue.getValue(),
|
333 |
| - meta.getValue() |
| 336 | + meta.getValue(), |
| 337 | + true |
334 | 338 | );
|
335 | 339 | ft.setBoost(boost.getValue());
|
336 | 340 | Long nullTimestamp = parseNullValue(ft);
|
@@ -372,15 +376,29 @@ public DateFieldType(
|
372 | 376 | DateFormatter dateTimeFormatter,
|
373 | 377 | Resolution resolution,
|
374 | 378 | String nullValue,
|
375 |
| - Map<String, String> meta |
| 379 | + Map<String, String> meta, |
| 380 | + boolean derivedSourceSupported |
376 | 381 | ) {
|
377 |
| - super(name, isSearchable, isStored, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta); |
| 382 | + super(name, isSearchable, isStored, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta, derivedSourceSupported); |
378 | 383 | this.dateTimeFormatter = dateTimeFormatter;
|
379 | 384 | this.dateMathParser = dateTimeFormatter.toDateMathParser();
|
380 | 385 | this.resolution = resolution;
|
381 | 386 | this.nullValue = nullValue;
|
382 | 387 | }
|
383 | 388 |
|
| 389 | + public DateFieldType( |
| 390 | + String name, |
| 391 | + boolean isSearchable, |
| 392 | + boolean isStored, |
| 393 | + boolean hasDocValues, |
| 394 | + DateFormatter dateTimeFormatter, |
| 395 | + Resolution resolution, |
| 396 | + String nullValue, |
| 397 | + Map<String, String> meta |
| 398 | + ) { |
| 399 | + this(name, isSearchable, isStored, hasDocValues, dateTimeFormatter, resolution, nullValue, meta, false); |
| 400 | + } |
| 401 | + |
384 | 402 | public DateFieldType(String name) {
|
385 | 403 | this(name, true, false, true, getDefaultDateTimeFormatter(), Resolution.MILLISECONDS, null, Collections.emptyMap());
|
386 | 404 | }
|
@@ -800,4 +818,18 @@ public boolean getIgnoreMalformed() {
|
800 | 818 | public Long getNullValue() {
|
801 | 819 | return nullValue;
|
802 | 820 | }
|
| 821 | + |
| 822 | + @Override |
| 823 | + protected String[] deriveSource(LeafReader leafReader, int docId) throws IOException { |
| 824 | + SortedNumericDocValues sortedNumericDocValues = leafReader.getSortedNumericDocValues(name()); |
| 825 | + if (sortedNumericDocValues.advanceExact(docId)) { |
| 826 | + int size = sortedNumericDocValues.docValueCount(); |
| 827 | + String[] values = new String[size]; |
| 828 | + DateFormatter dateFormatter = fieldType().dateTimeFormatter; |
| 829 | + for (int i = 0; i < size; i++) |
| 830 | + values[i] = dateFormatter.formatMillis(sortedNumericDocValues.nextValue()); |
| 831 | + return values; |
| 832 | + } |
| 833 | + return null; |
| 834 | + } |
803 | 835 | }
|
0 commit comments