Fix compile errors after elasticsearch-core master refactorings and multi-module builds

This commit is contained in:
Simon Willnauer 2015-06-08 11:46:06 +02:00
parent cf97e14ff0
commit f743ebb87f
8 changed files with 116 additions and 92 deletions

View File

@ -21,17 +21,19 @@ package org.elasticsearch.index.mapper.attachment;
import org.apache.lucene.document.Field; import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType; import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.util.CollectionUtil;
import org.apache.lucene.util.Constants; import org.apache.lucene.util.Constants;
import org.apache.tika.Tika; import org.apache.tika.Tika;
import org.apache.tika.language.LanguageIdentifier; import org.apache.tika.language.LanguageIdentifier;
import org.apache.tika.metadata.Metadata; import org.apache.tika.metadata.Metadata;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.common.collect.Iterators; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.collect.Lists;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.fielddata.FieldDataType;
@ -39,10 +41,7 @@ import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper; import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.*;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import static org.elasticsearch.index.mapper.MapperBuilders.*; import static org.elasticsearch.index.mapper.MapperBuilders.*;
import static org.elasticsearch.index.mapper.core.TypeParsers.parseMultiField; import static org.elasticsearch.index.mapper.core.TypeParsers.parseMultiField;
@ -90,6 +89,24 @@ public class AttachmentMapper extends AbstractFieldMapper {
public static final String LANGUAGE = "language"; public static final String LANGUAGE = "language";
} }
static final class AttachmentFieldType extends MappedFieldType {
public AttachmentFieldType() {
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
}
protected AttachmentFieldType(AttachmentMapper.AttachmentFieldType ref) {
super(ref);
}
public AttachmentMapper.AttachmentFieldType clone() {
return new AttachmentMapper.AttachmentFieldType(this);
}
public String value(Object value) {
return value == null?null:value.toString();
}
}
public static class Builder extends AbstractFieldMapper.Builder<Builder, AttachmentMapper> { public static class Builder extends AbstractFieldMapper.Builder<Builder, AttachmentMapper> {
private ContentPath.Type pathType = Defaults.PATH_TYPE; private ContentPath.Type pathType = Defaults.PATH_TYPE;
@ -119,7 +136,7 @@ public class AttachmentMapper extends AbstractFieldMapper {
private Mapper.Builder languageBuilder = stringField(FieldNames.LANGUAGE); private Mapper.Builder languageBuilder = stringField(FieldNames.LANGUAGE);
public Builder(String name) { public Builder(String name) {
super(name, new FieldType(AbstractFieldMapper.Defaults.FIELD_TYPE)); super(name, new AttachmentFieldType());
this.builder = this; this.builder = this;
this.contentBuilder = stringField(FieldNames.CONTENT); this.contentBuilder = stringField(FieldNames.CONTENT);
} }
@ -226,10 +243,24 @@ public class AttachmentMapper extends AbstractFieldMapper {
if (langDetect == null) { if (langDetect == null) {
langDetect = Boolean.FALSE; langDetect = Boolean.FALSE;
} }
MappedFieldType defaultFieldType = AbstractFieldMapper.Defaults.FIELD_TYPE.clone();
if(this.fieldType.indexOptions() != IndexOptions.NONE && !this.fieldType.tokenized()) {
defaultFieldType.setOmitNorms(true);
defaultFieldType.setIndexOptions(IndexOptions.DOCS);
if(!this.omitNormsSet && this.fieldType.boost() == 1.0F) {
this.fieldType.setOmitNorms(true);
}
return new AttachmentMapper(buildNames(context), pathType, defaultIndexedChars, ignoreErrors, langDetect, contentMapper, if(!this.indexOptionsSet) {
this.fieldType.setIndexOptions(IndexOptions.DOCS);
}
}
defaultFieldType.freeze();
this.setupFieldType(context);
return new AttachmentMapper(this.fieldType, pathType, defaultIndexedChars, ignoreErrors, langDetect, contentMapper,
dateMapper, titleMapper, nameMapper, authorMapper, keywordsMapper, contentTypeMapper, contentLength, dateMapper, titleMapper, nameMapper, authorMapper, keywordsMapper, contentTypeMapper, contentLength,
language, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); language, this.fieldDataSettings, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
} }
} }
@ -371,13 +402,12 @@ public class AttachmentMapper extends AbstractFieldMapper {
private final FieldMapper languageMapper; private final FieldMapper languageMapper;
public AttachmentMapper(Names names, ContentPath.Type pathType, int defaultIndexedChars, Boolean ignoreErrors, public AttachmentMapper(MappedFieldType type, ContentPath.Type pathType, int defaultIndexedChars, Boolean ignoreErrors,
Boolean defaultLangDetect, FieldMapper contentMapper, Boolean defaultLangDetect, FieldMapper contentMapper,
FieldMapper dateMapper, FieldMapper titleMapper, FieldMapper nameMapper, FieldMapper authorMapper, FieldMapper dateMapper, FieldMapper titleMapper, FieldMapper nameMapper, FieldMapper authorMapper,
FieldMapper keywordsMapper, FieldMapper contentTypeMapper, FieldMapper contentLengthMapper, FieldMapper keywordsMapper, FieldMapper contentTypeMapper, FieldMapper contentLengthMapper,
FieldMapper languageMapper, Settings indexSettings, MultiFields multiFields, CopyTo copyTo) { FieldMapper languageMapper, @Nullable Settings fieldDataSettings, Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
super(names, 1.0f, AbstractFieldMapper.Defaults.FIELD_TYPE, false, null, null, null, null, null, super(type, false, fieldDataSettings, indexSettings, multiFields, copyTo);
indexSettings, multiFields, copyTo);
this.pathType = pathType; this.pathType = pathType;
this.defaultIndexedChars = defaultIndexedChars; this.defaultIndexedChars = defaultIndexedChars;
this.ignoreErrors = ignoreErrors; this.ignoreErrors = ignoreErrors;
@ -394,12 +424,7 @@ public class AttachmentMapper extends AbstractFieldMapper {
} }
@Override @Override
public Object value(Object value) { public MappedFieldType defaultFieldType() {
return null;
}
@Override
public FieldType defaultFieldType() {
return AbstractFieldMapper.Defaults.FIELD_TYPE; return AbstractFieldMapper.Defaults.FIELD_TYPE;
} }
@ -611,17 +636,17 @@ public class AttachmentMapper extends AbstractFieldMapper {
@Override @Override
public Iterator<Mapper> iterator() { public Iterator<Mapper> iterator() {
List<FieldMapper> extras = Lists.newArrayList( List<FieldMapper> extras = Arrays.asList(
contentMapper, contentMapper,
dateMapper, dateMapper,
titleMapper, titleMapper,
nameMapper, nameMapper,
authorMapper, authorMapper,
keywordsMapper, keywordsMapper,
contentTypeMapper, contentTypeMapper,
contentLengthMapper, contentLengthMapper,
languageMapper); languageMapper);
return Iterators.concat(super.iterator(), extras.iterator()); return CollectionUtils.concat(super.iterator(), extras.iterator());
} }
@Override @Override

View File

@ -22,10 +22,9 @@ package org.elasticsearch.plugin.mapper.attachments;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Module;
import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.plugins.AbstractPlugin;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import static org.elasticsearch.common.collect.Lists.newArrayList;
/** /**
* *
*/ */
@ -43,7 +42,7 @@ public class MapperAttachmentsPlugin extends AbstractPlugin {
@Override @Override
public Collection<Class<? extends Module>> indexModules() { public Collection<Class<? extends Module>> indexModules() {
Collection<Class<? extends Module>> modules = newArrayList(); Collection<Class<? extends Module>> modules = new ArrayList<>();
modules.add(AttachmentsIndexModule.class); modules.add(AttachmentsIndexModule.class);
return modules; return modules;
} }

View File

@ -19,11 +19,11 @@
package org.elasticsearch.index.mapper.attachment.test.standalone; package org.elasticsearch.index.mapper.attachment.test.standalone;
import org.apache.commons.cli.CommandLine;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.cli.CliTool; import org.elasticsearch.common.cli.CliTool;
import org.elasticsearch.common.cli.CliToolConfig; import org.elasticsearch.common.cli.CliToolConfig;
import org.elasticsearch.common.cli.Terminal; import org.elasticsearch.common.cli.Terminal;
import org.elasticsearch.common.cli.commons.CommandLine;
import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -113,7 +113,7 @@ public class StandaloneRunner extends CliTool {
terminal.println("## Extracted text"); terminal.println("## Extracted text");
terminal.println("--------------------- BEGIN -----------------------"); terminal.println("--------------------- BEGIN -----------------------");
terminal.println("%s", doc.get(docMapper.mappers().getMapper("file").names().indexName())); terminal.println("%s", doc.get(docMapper.mappers().getMapper("file").fieldType().names().indexName()));
terminal.println("---------------------- END ------------------------"); terminal.println("---------------------- END ------------------------");
terminal.println("## Metadata"); terminal.println("## Metadata");
printMetadataContent(doc, AttachmentMapper.FieldNames.AUTHOR); printMetadataContent(doc, AttachmentMapper.FieldNames.AUTHOR);
@ -129,7 +129,7 @@ public class StandaloneRunner extends CliTool {
} }
private void printMetadataContent(ParseContext.Document doc, String field) { private void printMetadataContent(ParseContext.Document doc, String field) {
terminal.println("- %s: %s", field, doc.get(docMapper.mappers().getMapper("file." + field).names().indexName())); terminal.println("- %s: %s", field, doc.get(docMapper.mappers().getMapper("file." + field).fieldType().names().indexName()));
} }
public static byte[] copyToBytes(Path path) throws IOException { public static byte[] copyToBytes(Path path) throws IOException {

View File

@ -60,19 +60,19 @@ public class EncryptedDocMapperTest extends AttachmentUnitTestCase {
.endObject().bytes(); .endObject().bytes();
ParseContext.Document doc = docMapper.parse("person", "1", json).rootDoc(); ParseContext.Document doc = docMapper.parse("person", "1", json).rootDoc();
assertThat(doc.get(docMapper.mappers().getMapper("file1.content").names().indexName()), containsString("World")); assertThat(doc.get(docMapper.mappers().getMapper("file1.content").fieldType().names().indexName()), containsString("World"));
assertThat(doc.get(docMapper.mappers().getMapper("file1.title").names().indexName()), equalTo("Hello")); assertThat(doc.get(docMapper.mappers().getMapper("file1.title").fieldType().names().indexName()), equalTo("Hello"));
assertThat(doc.get(docMapper.mappers().getMapper("file1.author").names().indexName()), equalTo("kimchy")); assertThat(doc.get(docMapper.mappers().getMapper("file1.author").fieldType().names().indexName()), equalTo("kimchy"));
assertThat(doc.get(docMapper.mappers().getMapper("file1.keywords").names().indexName()), equalTo("elasticsearch,cool,bonsai")); assertThat(doc.get(docMapper.mappers().getMapper("file1.keywords").fieldType().names().indexName()), equalTo("elasticsearch,cool,bonsai"));
assertThat(doc.get(docMapper.mappers().getMapper("file1.content_type").names().indexName()), equalTo("text/html; charset=ISO-8859-1")); assertThat(doc.get(docMapper.mappers().getMapper("file1.content_type").fieldType().names().indexName()), equalTo("text/html; charset=ISO-8859-1"));
assertThat(doc.getField(docMapper.mappers().getMapper("file1.content_length").names().indexName()).numericValue().longValue(), is(344L)); assertThat(doc.getField(docMapper.mappers().getMapper("file1.content_length").fieldType().names().indexName()).numericValue().longValue(), is(344L));
assertThat(doc.get(docMapper.mappers().getMapper("file2").names().indexName()), nullValue()); assertThat(doc.get(docMapper.mappers().getMapper("file2").fieldType().names().indexName()), nullValue());
assertThat(doc.get(docMapper.mappers().getMapper("file2.title").names().indexName()), nullValue()); assertThat(doc.get(docMapper.mappers().getMapper("file2.title").fieldType().names().indexName()), nullValue());
assertThat(doc.get(docMapper.mappers().getMapper("file2.author").names().indexName()), nullValue()); assertThat(doc.get(docMapper.mappers().getMapper("file2.author").fieldType().names().indexName()), nullValue());
assertThat(doc.get(docMapper.mappers().getMapper("file2.keywords").names().indexName()), nullValue()); assertThat(doc.get(docMapper.mappers().getMapper("file2.keywords").fieldType().names().indexName()), nullValue());
assertThat(doc.get(docMapper.mappers().getMapper("file2.content_type").names().indexName()), nullValue()); assertThat(doc.get(docMapper.mappers().getMapper("file2.content_type").fieldType().names().indexName()), nullValue());
assertThat(doc.getField(docMapper.mappers().getMapper("file2.content_length").names().indexName()), nullValue()); assertThat(doc.getField(docMapper.mappers().getMapper("file2.content_length").fieldType().names().indexName()), nullValue());
} }
@Test @Test
@ -92,19 +92,19 @@ public class EncryptedDocMapperTest extends AttachmentUnitTestCase {
.endObject().bytes(); .endObject().bytes();
ParseContext.Document doc = docMapper.parse("person", "1", json).rootDoc(); ParseContext.Document doc = docMapper.parse("person", "1", json).rootDoc();
assertThat(doc.get(docMapper.mappers().getMapper("file1").names().indexName()), nullValue()); assertThat(doc.get(docMapper.mappers().getMapper("file1").fieldType().names().indexName()), nullValue());
assertThat(doc.get(docMapper.mappers().getMapper("file1.title").names().indexName()), nullValue()); assertThat(doc.get(docMapper.mappers().getMapper("file1.title").fieldType().names().indexName()), nullValue());
assertThat(doc.get(docMapper.mappers().getMapper("file1.author").names().indexName()), nullValue()); assertThat(doc.get(docMapper.mappers().getMapper("file1.author").fieldType().names().indexName()), nullValue());
assertThat(doc.get(docMapper.mappers().getMapper("file1.keywords").names().indexName()), nullValue()); assertThat(doc.get(docMapper.mappers().getMapper("file1.keywords").fieldType().names().indexName()), nullValue());
assertThat(doc.get(docMapper.mappers().getMapper("file1.content_type").names().indexName()), nullValue()); assertThat(doc.get(docMapper.mappers().getMapper("file1.content_type").fieldType().names().indexName()), nullValue());
assertThat(doc.getField(docMapper.mappers().getMapper("file1.content_length").names().indexName()), nullValue()); assertThat(doc.getField(docMapper.mappers().getMapper("file1.content_length").fieldType().names().indexName()), nullValue());
assertThat(doc.get(docMapper.mappers().getMapper("file2.content").names().indexName()), containsString("World")); assertThat(doc.get(docMapper.mappers().getMapper("file2.content").fieldType().names().indexName()), containsString("World"));
assertThat(doc.get(docMapper.mappers().getMapper("file2.title").names().indexName()), equalTo("Hello")); assertThat(doc.get(docMapper.mappers().getMapper("file2.title").fieldType().names().indexName()), equalTo("Hello"));
assertThat(doc.get(docMapper.mappers().getMapper("file2.author").names().indexName()), equalTo("kimchy")); assertThat(doc.get(docMapper.mappers().getMapper("file2.author").fieldType().names().indexName()), equalTo("kimchy"));
assertThat(doc.get(docMapper.mappers().getMapper("file2.keywords").names().indexName()), equalTo("elasticsearch,cool,bonsai")); assertThat(doc.get(docMapper.mappers().getMapper("file2.keywords").fieldType().names().indexName()), equalTo("elasticsearch,cool,bonsai"));
assertThat(doc.get(docMapper.mappers().getMapper("file2.content_type").names().indexName()), equalTo("text/html; charset=ISO-8859-1")); assertThat(doc.get(docMapper.mappers().getMapper("file2.content_type").fieldType().names().indexName()), equalTo("text/html; charset=ISO-8859-1"));
assertThat(doc.getField(docMapper.mappers().getMapper("file2.content_length").names().indexName()).numericValue().longValue(), is(344L)); assertThat(doc.getField(docMapper.mappers().getMapper("file2.content_length").fieldType().names().indexName()).numericValue().longValue(), is(344L));
} }
@Test(expected = MapperParsingException.class) @Test(expected = MapperParsingException.class)
@ -128,19 +128,19 @@ public class EncryptedDocMapperTest extends AttachmentUnitTestCase {
.endObject().bytes(); .endObject().bytes();
ParseContext.Document doc = docMapper.parse("person", "1", json).rootDoc(); ParseContext.Document doc = docMapper.parse("person", "1", json).rootDoc();
assertThat(doc.get(docMapper.mappers().getMapper("file1").names().indexName()), nullValue()); assertThat(doc.get(docMapper.mappers().getMapper("file1").fieldType().names().indexName()), nullValue());
assertThat(doc.get(docMapper.mappers().getMapper("file1.title").names().indexName()), nullValue()); assertThat(doc.get(docMapper.mappers().getMapper("file1.title").fieldType().names().indexName()), nullValue());
assertThat(doc.get(docMapper.mappers().getMapper("file1.author").names().indexName()), nullValue()); assertThat(doc.get(docMapper.mappers().getMapper("file1.author").fieldType().names().indexName()), nullValue());
assertThat(doc.get(docMapper.mappers().getMapper("file1.keywords").names().indexName()), nullValue()); assertThat(doc.get(docMapper.mappers().getMapper("file1.keywords").fieldType().names().indexName()), nullValue());
assertThat(doc.get(docMapper.mappers().getMapper("file1.content_type").names().indexName()), nullValue()); assertThat(doc.get(docMapper.mappers().getMapper("file1.content_type").fieldType().names().indexName()), nullValue());
assertThat(doc.getField(docMapper.mappers().getMapper("file1.content_length").names().indexName()), nullValue()); assertThat(doc.getField(docMapper.mappers().getMapper("file1.content_length").fieldType().names().indexName()), nullValue());
assertThat(doc.get(docMapper.mappers().getMapper("file2").names().indexName()), containsString("World")); assertThat(doc.get(docMapper.mappers().getMapper("file2").fieldType().names().indexName()), containsString("World"));
assertThat(doc.get(docMapper.mappers().getMapper("file2.title").names().indexName()), equalTo("Hello")); assertThat(doc.get(docMapper.mappers().getMapper("file2.title").fieldType().names().indexName()), equalTo("Hello"));
assertThat(doc.get(docMapper.mappers().getMapper("file2.author").names().indexName()), equalTo("kimchy")); assertThat(doc.get(docMapper.mappers().getMapper("file2.author").fieldType().names().indexName()), equalTo("kimchy"));
assertThat(doc.get(docMapper.mappers().getMapper("file2.keywords").names().indexName()), equalTo("elasticsearch,cool,bonsai")); assertThat(doc.get(docMapper.mappers().getMapper("file2.keywords").fieldType().names().indexName()), equalTo("elasticsearch,cool,bonsai"));
assertThat(doc.get(docMapper.mappers().getMapper("file2.content_type").names().indexName()), equalTo("text/html; charset=ISO-8859-1")); assertThat(doc.get(docMapper.mappers().getMapper("file2.content_type").fieldType().names().indexName()), equalTo("text/html; charset=ISO-8859-1"));
assertThat(doc.getField(docMapper.mappers().getMapper("file2.content_length").names().indexName()).numericValue().longValue(), is(344L)); assertThat(doc.getField(docMapper.mappers().getMapper("file2.content_length").fieldType().names().indexName()).numericValue().longValue(), is(344L));
} }
} }

View File

@ -81,7 +81,7 @@ public class LanguageDetectionAttachmentMapperTests extends AttachmentUnitTestCa
ParseContext.Document doc = docMapper.parse("person", "1", xcb.bytes()).rootDoc(); ParseContext.Document doc = docMapper.parse("person", "1", xcb.bytes()).rootDoc();
// Our mapping should be kept as a String // Our mapping should be kept as a String
assertThat(doc.get(docMapper.mappers().getMapper("file.language").names().indexName()), equalTo(expected)); assertThat(doc.get(docMapper.mappers().getMapper("file.language").fieldType().names().indexName()), equalTo(expected));
} }
@Test @Test
@ -133,6 +133,6 @@ public class LanguageDetectionAttachmentMapperTests extends AttachmentUnitTestCa
ParseContext.Document doc = docMapper.parse("person", "1", xcb.bytes()).rootDoc(); ParseContext.Document doc = docMapper.parse("person", "1", xcb.bytes()).rootDoc();
// Our mapping should be kept as a String // Our mapping should be kept as a String
assertThat(doc.get(docMapper.mappers().getMapper("file.language").names().indexName()), equalTo("en")); assertThat(doc.get(docMapper.mappers().getMapper("file.language").fieldType().names().indexName()), equalTo("en"));
} }
} }

View File

@ -64,18 +64,18 @@ public class MetadataMapperTest extends AttachmentUnitTestCase {
.endObject().bytes(); .endObject().bytes();
ParseContext.Document doc = docMapper.parse("person", "1", json).rootDoc(); ParseContext.Document doc = docMapper.parse("person", "1", json).rootDoc();
assertThat(doc.get(docMapper.mappers().getMapper("file.content").names().indexName()), containsString("World")); assertThat(doc.get(docMapper.mappers().getMapper("file.content").fieldType().names().indexName()), containsString("World"));
assertThat(doc.get(docMapper.mappers().getMapper("file.name").names().indexName()), equalTo(filename)); assertThat(doc.get(docMapper.mappers().getMapper("file.name").fieldType().names().indexName()), equalTo(filename));
if (expectedDate == null) { if (expectedDate == null) {
assertThat(doc.getField(docMapper.mappers().getMapper("file.date").names().indexName()), nullValue()); assertThat(doc.getField(docMapper.mappers().getMapper("file.date").fieldType().names().indexName()), nullValue());
} else { } else {
assertThat(doc.getField(docMapper.mappers().getMapper("file.date").names().indexName()).numericValue().longValue(), is(expectedDate)); assertThat(doc.getField(docMapper.mappers().getMapper("file.date").fieldType().names().indexName()).numericValue().longValue(), is(expectedDate));
} }
assertThat(doc.get(docMapper.mappers().getMapper("file.title").names().indexName()), equalTo("Hello")); assertThat(doc.get(docMapper.mappers().getMapper("file.title").fieldType().names().indexName()), equalTo("Hello"));
assertThat(doc.get(docMapper.mappers().getMapper("file.author").names().indexName()), equalTo("kimchy")); assertThat(doc.get(docMapper.mappers().getMapper("file.author").fieldType().names().indexName()), equalTo("kimchy"));
assertThat(doc.get(docMapper.mappers().getMapper("file.keywords").names().indexName()), equalTo("elasticsearch,cool,bonsai")); assertThat(doc.get(docMapper.mappers().getMapper("file.keywords").fieldType().names().indexName()), equalTo("elasticsearch,cool,bonsai"));
assertThat(doc.get(docMapper.mappers().getMapper("file.content_type").names().indexName()), equalTo("text/html; charset=ISO-8859-1")); assertThat(doc.get(docMapper.mappers().getMapper("file.content_type").fieldType().names().indexName()), equalTo("text/html; charset=ISO-8859-1"));
assertThat(doc.getField(docMapper.mappers().getMapper("file.content_length").names().indexName()).numericValue().longValue(), is(expectedLength)); assertThat(doc.getField(docMapper.mappers().getMapper("file.content_length").fieldType().names().indexName()).numericValue().longValue(), is(expectedLength));
} }
@Test @Test

View File

@ -53,9 +53,9 @@ public class SimpleAttachmentMapperTests extends AttachmentUnitTestCase {
ParseContext.Document doc = docMapper.parse("person", "1", json).rootDoc(); ParseContext.Document doc = docMapper.parse("person", "1", json).rootDoc();
assertThat(doc.get(docMapper.mappers().getMapper("file.content_type").names().indexName()), startsWith("application/xhtml+xml")); assertThat(doc.get(docMapper.mappers().getMapper("file.content_type").fieldType().names().indexName()), startsWith("application/xhtml+xml"));
assertThat(doc.get(docMapper.mappers().getMapper("file.title").names().indexName()), equalTo("XHTML test document")); assertThat(doc.get(docMapper.mappers().getMapper("file.title").fieldType().names().indexName()), equalTo("XHTML test document"));
assertThat(doc.get(docMapper.mappers().getMapper("file.content").names().indexName()), containsString("This document tests the ability of Apache Tika to extract content")); assertThat(doc.get(docMapper.mappers().getMapper("file.content").fieldType().names().indexName()), containsString("This document tests the ability of Apache Tika to extract content"));
// re-parse it // re-parse it
String builtMapping = docMapper.mappingSource().string(); String builtMapping = docMapper.mappingSource().string();
@ -65,9 +65,9 @@ public class SimpleAttachmentMapperTests extends AttachmentUnitTestCase {
doc = docMapper.parse("person", "1", json).rootDoc(); doc = docMapper.parse("person", "1", json).rootDoc();
assertThat(doc.get(docMapper.mappers().getMapper("file.content_type").names().indexName()), startsWith("application/xhtml+xml")); assertThat(doc.get(docMapper.mappers().getMapper("file.content_type").fieldType().names().indexName()), startsWith("application/xhtml+xml"));
assertThat(doc.get(docMapper.mappers().getMapper("file.title").names().indexName()), equalTo("XHTML test document")); assertThat(doc.get(docMapper.mappers().getMapper("file.title").fieldType().names().indexName()), equalTo("XHTML test document"));
assertThat(doc.get(docMapper.mappers().getMapper("file.content").names().indexName()), containsString("This document tests the ability of Apache Tika to extract content")); assertThat(doc.get(docMapper.mappers().getMapper("file.content").fieldType().names().indexName()), containsString("This document tests the ability of Apache Tika to extract content"));
} }
public void testContentBackcompat() throws Exception { public void testContentBackcompat() throws Exception {

View File

@ -141,8 +141,8 @@ public class VariousDocTest extends AttachmentUnitTestCase {
ParseContext.Document doc = docMapper.parse("person", "1", json).rootDoc(); ParseContext.Document doc = docMapper.parse("person", "1", json).rootDoc();
if (!errorExpected) { if (!errorExpected) {
assertThat(doc.get(docMapper.mappers().getMapper("file.content").names().indexName()), not(isEmptyOrNullString())); assertThat(doc.get(docMapper.mappers().getMapper("file.content").fieldType().names().indexName()), not(isEmptyOrNullString()));
logger.debug("-> extracted content: {}", doc.get(docMapper.mappers().getMapper("file").names().indexName())); logger.debug("-> extracted content: {}", doc.get(docMapper.mappers().getMapper("file").fieldType().names().indexName()));
logger.debug("-> extracted metadata:"); logger.debug("-> extracted metadata:");
printMetadataContent(doc, AUTHOR); printMetadataContent(doc, AUTHOR);
printMetadataContent(doc, CONTENT_LENGTH); printMetadataContent(doc, CONTENT_LENGTH);
@ -156,6 +156,6 @@ public class VariousDocTest extends AttachmentUnitTestCase {
} }
private void printMetadataContent(ParseContext.Document doc, String field) { private void printMetadataContent(ParseContext.Document doc, String field) {
logger.debug("- [{}]: [{}]", field, doc.get(docMapper.mappers().getMapper("file." + field).names().indexName())); logger.debug("- [{}]: [{}]", field, doc.get(docMapper.mappers().getMapper("file." + field).fieldType().names().indexName()));
} }
} }