DateMapper extends SingleColumnMapper.SingleFieldMapper<Long> { @Override public Optional<Field> indexedField(String name, Long value) { return Optional.of(new LongField(name, value, STORE)); } 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 testIndexedField() throws ParseException { long base = new SimpleDateFormat("yyyyMMdd").parse("20161127").getTime(); DateMapper mapper = dateMapper().pattern("yyyyMMdd").build("name"); Field field = mapper.indexedField("name", base) .orElseThrow(() -> new AssertionError("Indexed field is not created")); assertEquals("Indexed field value is wrong", base, field.numericValue().longValue()); assertEquals("Indexed field name is wrong", "name", field.name()); assertEquals("Indexed field type is wrong", false, field.fieldType().stored()); }