public void testDefaults() throws Exception { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "keyword").endObject().endObject() .endObject().endObject().string(); DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder() .startObject() .field("field", "1234") .endObject() .bytes()); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); assertEquals(new BytesRef("1234"), fields[0].binaryValue()); IndexableFieldType fieldType = fields[0].fieldType(); assertThat(fieldType.omitNorms(), equalTo(true)); assertFalse(fieldType.tokenized()); assertFalse(fieldType.stored()); assertThat(fieldType.indexOptions(), equalTo(IndexOptions.DOCS)); assertThat(fieldType.storeTermVectors(), equalTo(false)); assertThat(fieldType.storeTermVectorOffsets(), equalTo(false)); assertThat(fieldType.storeTermVectorPositions(), equalTo(false)); assertThat(fieldType.storeTermVectorPayloads(), equalTo(false)); assertEquals(DocValuesType.NONE, fieldType.docValuesType()); assertEquals(new BytesRef("1234"), fields[1].binaryValue()); fieldType = fields[1].fieldType(); assertThat(fieldType.indexOptions(), equalTo(IndexOptions.NONE)); assertEquals(DocValuesType.SORTED_SET, fieldType.docValuesType()); }
public void testNormalizer() throws IOException { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") .field("type", "keyword").field("normalizer", "my_lowercase").endObject().endObject() .endObject().endObject().string(); DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder() .startObject() .field("field", "AbC") .endObject() .bytes()); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); assertEquals(new BytesRef("abc"), fields[0].binaryValue()); IndexableFieldType fieldType = fields[0].fieldType(); assertThat(fieldType.omitNorms(), equalTo(true)); assertFalse(fieldType.tokenized()); assertFalse(fieldType.stored()); assertThat(fieldType.indexOptions(), equalTo(IndexOptions.DOCS)); assertThat(fieldType.storeTermVectors(), equalTo(false)); assertThat(fieldType.storeTermVectorOffsets(), equalTo(false)); assertThat(fieldType.storeTermVectorPositions(), equalTo(false)); assertThat(fieldType.storeTermVectorPayloads(), equalTo(false)); assertEquals(DocValuesType.NONE, fieldType.docValuesType()); assertEquals(new BytesRef("abc"), fields[1].binaryValue()); fieldType = fields[1].fieldType(); assertThat(fieldType.indexOptions(), equalTo(IndexOptions.NONE)); assertEquals(DocValuesType.SORTED_SET, fieldType.docValuesType()); }
public void testDefaults() throws Exception { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "text").endObject().endObject() .endObject().endObject().string(); DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder() .startObject() .field("field", "1234") .endObject() .bytes()); IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(1, fields.length); assertEquals("1234", fields[0].stringValue()); IndexableFieldType fieldType = fields[0].fieldType(); assertThat(fieldType.omitNorms(), equalTo(false)); assertTrue(fieldType.tokenized()); assertFalse(fieldType.stored()); assertThat(fieldType.indexOptions(), equalTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)); assertThat(fieldType.storeTermVectors(), equalTo(false)); assertThat(fieldType.storeTermVectorOffsets(), equalTo(false)); assertThat(fieldType.storeTermVectorPositions(), equalTo(false)); assertThat(fieldType.storeTermVectorPayloads(), equalTo(false)); assertEquals(DocValuesType.NONE, fieldType.docValuesType()); }
public static FieldType from(IndexableFieldType indexableFieldType) { final FieldType fieldType = new FieldType(); fieldType.setStored(indexableFieldType.stored()); fieldType.setIndexed(indexableFieldType.indexed()); fieldType.setIndexOptions(indexableFieldType.indexOptions()); fieldType.setStoreTermVectors(indexableFieldType.storeTermVectors()); fieldType.setStoreTermVectorPositions(indexableFieldType.storeTermVectorPositions()); fieldType.setStoreTermVectorPayloads(indexableFieldType.storeTermVectorPayloads()); fieldType.setStoreTermVectorOffsets(indexableFieldType.storeTermVectorOffsets()); fieldType.setDocValueType(indexableFieldType.docValueType()); fieldType.setOmitNorms(indexableFieldType.omitNorms()); fieldType.setTokenized(indexableFieldType.tokenized()); return fieldType; }
@Test public void testTextField() { JsonArray json = Json.createArrayBuilder() .add(Json.createObjectBuilder() .add("type", "TextField") .add("name", "name") .add("value", "value")) .build(); Document result = convert(json.toString()); IndexableFieldType fieldType = result.getField("name").fieldType(); assertEquals(TextField.TYPE_NOT_STORED, fieldType); assertFalse(fieldType.storeTermVectors()); assertEquals("value", result.getField("name").stringValue()); }
@Test public void testTextFieldWithTermVectors() { JsonArray json = Json.createArrayBuilder() .add(Json.createObjectBuilder() .add("type", "TextField") .add("termVectors", JsonValue.TRUE) .add("name", "name") .add("value", "value")) .build(); Document result = convert(json.toString()); IndexableFieldType fieldType = result.getField("name").fieldType(); assertTrue(fieldType.storeTermVectors()); assertEquals("value", result.getField("name").stringValue()); }
@Override public IndexableFieldType fieldType() { return TYPE; }
@Override public IndexableFieldType fieldType() { return getRealValue().fieldType(); }
private ObjectField(String name, Object object, IndexableFieldType type, float boost) { this.name = name; this.object = object; this.type = type; this.boost = boost; }
@Override public IndexableFieldType fieldType() { return type; }