TextMapper extends SingleColumnMapper.SingleFieldMapper<String> { public TextMapper(String field, String column, Boolean validated, String analyzer) { super(field, column, false, validated, analyzer, String.class, PRINTABLE_TYPES); } TextMapper(String field, String column, Boolean validated, String analyzer); @Override Optional<Field> indexedField(String name, String value); @Override Optional<Field> sortedField(String name, String value); @Override SortField sortField(String name, boolean reverse); @Override String toString();  }
@Test public void testConstructorWithoutArgs() { TextMapper mapper = textMapper().build("field"); assertEquals("Field is not set", "field", mapper.field); assertEquals("Column is not set to default value", "field", mapper.column); assertEquals("Mapped columns are not set", 1, mapper.mappedColumns.size()); assertTrue("Mapped columns are not set", mapper.mappedColumns.contains("field")); assertNull("Analyzer is not set to default value", mapper.analyzer); }
@Test public void testConstructorWithAllArgs() { TextMapper mapper = textMapper().column("column").analyzer("spanish").build("field"); assertEquals("Field is not set", "field", mapper.field); assertEquals("Column is not set", "column", mapper.column); assertEquals("Mapped columns are not set", 1, mapper.mappedColumns.size()); assertTrue("Mapped columns are not set", mapper.mappedColumns.contains("column")); assertEquals("Analyzer is not set", "spanish", mapper.analyzer); }
@Test public void testJsonSerialization() { TextMapperBuilder builder = textMapper().column("column").analyzer("spanish"); testJson(builder, "{type:\"text\",column:\"column\",analyzer:\"spanish\"}"); }
@Test public void testJsonSerializationDefaults() { TextMapperBuilder builder = textMapper(); testJson(builder, "{type:\"text\"}"); }
@Test public void testBaseClass() { TextMapper mapper = textMapper().analyzer("SpanishAnalyzer").build("field"); assertEquals("Base class is wrong", String.class, mapper.base); }
@Test public void testValueNull() { TextMapper mapper = textMapper().build("field"); assertNull("Base for nulls is wrong", mapper.base("test", null)); }
@Test public void testValueInteger() { TextMapper mapper = textMapper().analyzer("org.apache.lucene.analysis.en.EnglishAnalyzer").build("field"); String parsed = mapper.base("test", 3); assertEquals("Base for integers is wrong", "3", parsed); }
@Test public void testValueLong() { TextMapper mapper = textMapper().analyzer("org.apache.lucene.analysis.en.EnglishAnalyzer").build("field"); String parsed = mapper.base("test", 3l); assertEquals("Base for longs is wrong", "3", parsed); }
@Test public void testValueShort() { TextMapper mapper = textMapper().analyzer("org.apache.lucene.analysis.en.EnglishAnalyzer").build("field"); String parsed = mapper.base("test", new Short("3")); assertEquals("Base for longs is wrong", "3", parsed); }
@Test public void testValueByte() { TextMapper mapper = textMapper().analyzer("org.apache.lucene.analysis.en.EnglishAnalyzer").build("field"); String parsed = mapper.base("test", new Byte("3")); assertEquals("Base for longs is wrong", "3", parsed); }
@Test public void testValueFloatWithoutDecimal() { TextMapper mapper = textMapper().analyzer("org.apache.lucene.analysis.en.EnglishAnalyzer").build("field"); String parsed = mapper.base("test", 3f); assertEquals("Base for floats is wrong", "3.0", parsed); }
@Test public void testValueFloatWithDecimalFloor() { TextMapper mapper = textMapper().analyzer("org.apache.lucene.analysis.en.EnglishAnalyzer").build("field"); String parsed = mapper.base("test", 3.5f); assertEquals("Base for floats is wrong", "3.5", parsed); }
@Test public void testValueFloatWithDecimalCeil() { TextMapper mapper = textMapper().analyzer("org.apache.lucene.analysis.en.EnglishAnalyzer").build("field"); String parsed = mapper.base("test", 3.6f); assertEquals("Base for floats is wrong", "3.6", parsed); }
@Test public void testValueDoubleWithoutDecimal() { TextMapper mapper = textMapper().analyzer("org.apache.lucene.analysis.en.EnglishAnalyzer").build("field"); String parsed = mapper.base("test", 3d); assertEquals("Base for doubles is wrong", "3.0", parsed); }
@Test public void testValueDoubleWithDecimalFloor() { TextMapper mapper = textMapper().analyzer("org.apache.lucene.analysis.en.EnglishAnalyzer").build("field"); String parsed = mapper.base("test", 3.5d); assertEquals("Base for doubles is wrong", "3.5", parsed); }
@Test public void testValueDoubleWithDecimalCeil() { TextMapper mapper = textMapper().analyzer("org.apache.lucene.analysis.en.EnglishAnalyzer").build("field"); String parsed = mapper.base("test", 3.6d); assertEquals("Base for doubles is wrong", "3.6", parsed); }
@Test public void testValueStringWithoutDecimal() { TextMapper mapper = textMapper().analyzer("org.apache.lucene.analysis.en.EnglishAnalyzer").build("field"); String parsed = mapper.base("test", "3"); assertEquals("Base for strings is wrong", "3", parsed); }
@Test public void testValueStringWithDecimalFloor() { TextMapper mapper = textMapper().analyzer("org.apache.lucene.analysis.en.EnglishAnalyzer").build("field"); String parsed = mapper.base("test", "3.2"); assertEquals("Base for strings is wrong", "3.2", parsed); }
@Test public void testValueStringWithDecimalCeil() { TextMapper mapper = textMapper().analyzer("org.apache.lucene.analysis.en.EnglishAnalyzer").build("field"); String parsed = mapper.base("test", "3.6"); assertEquals("Base for strings is wrong", "3.6", parsed); }
@Test public void testValueUUID() { TextMapper mapper = textMapper().analyzer("org.apache.lucene.analysis.en.EnglishAnalyzer").build("field"); String parsed = mapper.base("test", UUID.fromString("550e8400-e29b-41d4-a716-446655440000")); assertEquals("Base for UUIDs is wrong", "550e8400-e29b-41d4-a716-446655440000", parsed); }
@Test public void testExtractAnalyzers() { TextMapper mapper = textMapper().analyzer("org.apache.lucene.analysis.en.EnglishAnalyzer").build("field"); assertEquals("Method #analyzer is wrong", "org.apache.lucene.analysis.en.EnglishAnalyzer", mapper.analyzer); }