Add a fineName field to index the attchment fileName

This commit is contained in:
alheim 2012-03-15 17:10:12 +01:00 committed by Shay Banon
parent 911fa246d0
commit d9a822dba8
1 changed files with 22 additions and 2 deletions

View File

@ -72,6 +72,8 @@ public class AttachmentMapper implements Mapper {
private StringFieldMapper.Builder contentBuilder;
private StringFieldMapper.Builder titleBuilder = stringField("title");
private StringFieldMapper.Builder fileNameBuilder = stringField("fileName");
private StringFieldMapper.Builder authorBuilder = stringField("author");
@ -116,6 +118,11 @@ public class AttachmentMapper implements Mapper {
this.titleBuilder = title;
return this;
}
public Builder fileName(StringFieldMapper.Builder fileName) {
this.fileNameBuilder = fileName;
return this;
}
public Builder keywords(StringFieldMapper.Builder keywords) {
this.keywordsBuilder = keywords;
@ -140,6 +147,7 @@ public class AttachmentMapper implements Mapper {
DateFieldMapper dateMapper = dateBuilder.build(context);
StringFieldMapper authorMapper = authorBuilder.build(context);
StringFieldMapper titleMapper = titleBuilder.build(context);
StringFieldMapper fileNameMapper = fileNameBuilder.build(context);
StringFieldMapper keywordsMapper = keywordsBuilder.build(context);
StringFieldMapper contentTypeMapper = contentTypeBuilder.build(context);
context.path().remove();
@ -153,7 +161,7 @@ public class AttachmentMapper implements Mapper {
defaultIndexedChars = 100000;
}
return new AttachmentMapper(name, pathType, defaultIndexedChars, contentMapper, dateMapper, titleMapper, authorMapper, keywordsMapper, contentTypeMapper);
return new AttachmentMapper(name, pathType, defaultIndexedChars, contentMapper, dateMapper, titleMapper, fileNameMapper, authorMapper, keywordsMapper, contentTypeMapper);
}
}
@ -198,6 +206,8 @@ public class AttachmentMapper implements Mapper {
builder.date((DateFieldMapper.Builder) parserContext.typeParser("date").parse("date", (Map<String, Object>) propNode, parserContext));
} else if ("title".equals(propName)) {
builder.title((StringFieldMapper.Builder) parserContext.typeParser("string").parse("title", (Map<String, Object>) propNode, parserContext));
} else if ("fileName".equals(propName)) {
builder.fileName((StringFieldMapper.Builder) parserContext.typeParser("string").parse("fileName", (Map<String, Object>) propNode, parserContext));
} else if ("author".equals(propName)) {
builder.author((StringFieldMapper.Builder) parserContext.typeParser("string").parse("author", (Map<String, Object>) propNode, parserContext));
} else if ("keywords".equals(propName)) {
@ -226,13 +236,15 @@ public class AttachmentMapper implements Mapper {
private final StringFieldMapper authorMapper;
private final StringFieldMapper titleMapper;
private final StringFieldMapper fileNameMapper;
private final StringFieldMapper keywordsMapper;
private final StringFieldMapper contentTypeMapper;
public AttachmentMapper(String name, ContentPath.Type pathType, int defaultIndexedChars, StringFieldMapper contentMapper,
DateFieldMapper dateMapper, StringFieldMapper titleMapper, StringFieldMapper authorMapper,
DateFieldMapper dateMapper, StringFieldMapper titleMapper, StringFieldMapper fileNameMapper, StringFieldMapper authorMapper,
StringFieldMapper keywordsMapper, StringFieldMapper contentTypeMapper) {
this.name = name;
this.pathType = pathType;
@ -240,6 +252,7 @@ public class AttachmentMapper implements Mapper {
this.contentMapper = contentMapper;
this.dateMapper = dateMapper;
this.titleMapper = titleMapper;
this.fileNameMapper = fileNameMapper;
this.authorMapper = authorMapper;
this.keywordsMapper = keywordsMapper;
this.contentTypeMapper = contentTypeMapper;
@ -301,6 +314,10 @@ public class AttachmentMapper implements Mapper {
context.externalValue(parsedContent);
contentMapper.parse(context);
context.externalValue(name);
fileNameMapper.parse(context);
context.externalValue(metadata.get(Metadata.DATE));
dateMapper.parse(context);
@ -327,6 +344,7 @@ public class AttachmentMapper implements Mapper {
contentMapper.traverse(fieldMapperListener);
dateMapper.traverse(fieldMapperListener);
titleMapper.traverse(fieldMapperListener);
fileNameMapper.traverse(fieldMapperListener);
authorMapper.traverse(fieldMapperListener);
keywordsMapper.traverse(fieldMapperListener);
contentTypeMapper.traverse(fieldMapperListener);
@ -341,6 +359,7 @@ public class AttachmentMapper implements Mapper {
contentMapper.close();
dateMapper.close();
titleMapper.close();
fileNameMapper.close();
authorMapper.close();
keywordsMapper.close();
contentTypeMapper.close();
@ -356,6 +375,7 @@ public class AttachmentMapper implements Mapper {
contentMapper.toXContent(builder, params);
authorMapper.toXContent(builder, params);
titleMapper.toXContent(builder, params);
fileNameMapper.toXContent(builder, params);
dateMapper.toXContent(builder, params);
keywordsMapper.toXContent(builder, params);
contentTypeMapper.toXContent(builder, params);