DateMapper extends SingleColumnMapper.SingleFieldMapper<Long> { @Override public Optional<Field> sortedField(String name, Long value) { return Optional.of(new SortedNumericDocValuesField(name, value)); } DateMapper(String field, String column, Boolean validated, String pattern); @Override Optional<Field> indexedField(String name, Long value); @Override Optional<Field> sortedField(String name, Long value); @Override SortField sortField(String name, boolean reverse); @Override String toString(); final DateParser parser; }
@Test public void testSortedField() throws ParseException { long base = new SimpleDateFormat("yyyyMMdd").parse("20161127").getTime(); DateMapper mapper = dateMapper().pattern("yyyyMMdd").build("name"); Field field = mapper.sortedField("name", base) .orElseThrow(() -> new AssertionError("Sorted field is not created")); assertEquals("Sorted field type is wrong", DocValuesType.SORTED_NUMERIC, field.fieldType().docValuesType()); }