rename field to path in _analyzer mapping

This commit is contained in:
kimchy 2010-11-08 11:07:34 +02:00
parent c9228ed26d
commit c69b94d769
3 changed files with 12 additions and 12 deletions

View File

@ -60,7 +60,7 @@ public class AnalyzerMapper implements XContentMapper {
// for (Map.Entry<String, Object> entry : node.entrySet()) { // for (Map.Entry<String, Object> entry : node.entrySet()) {
// String fieldName = Strings.toUnderscoreCase(entry.getKey()); // String fieldName = Strings.toUnderscoreCase(entry.getKey());
// Object fieldNode = entry.getValue(); // Object fieldNode = entry.getValue();
// if ("field".equals(fieldName)) { // if ("path".equals(fieldName)) {
// builder.field(fieldNode.toString()); // builder.field(fieldNode.toString());
// } // }
// } // }
@ -68,10 +68,10 @@ public class AnalyzerMapper implements XContentMapper {
// } // }
// } // }
private final String field; private final String path;
public AnalyzerMapper(String field) { public AnalyzerMapper(String path) {
this.field = field; this.path = path;
} }
@Override public String name() { @Override public String name() {
@ -80,12 +80,12 @@ public class AnalyzerMapper implements XContentMapper {
@Override public void parse(ParseContext context) throws IOException { @Override public void parse(ParseContext context) throws IOException {
Analyzer analyzer = context.docMapper().mappers().indexAnalyzer(); Analyzer analyzer = context.docMapper().mappers().indexAnalyzer();
if (field != null) { if (path != null) {
String value = context.doc().get(field); String value = context.doc().get(path);
if (value != null) { if (value != null) {
analyzer = context.analysisService().analyzer(value); analyzer = context.analysisService().analyzer(value);
if (analyzer == null) { if (analyzer == null) {
throw new MapperParsingException("No analyzer found for [" + value + "] from field [" + field + "]"); throw new MapperParsingException("No analyzer found for [" + value + "] from path [" + path + "]");
} }
analyzer = context.docMapper().mappers().indexAnalyzer(analyzer); analyzer = context.docMapper().mappers().indexAnalyzer(analyzer);
} }
@ -100,12 +100,12 @@ public class AnalyzerMapper implements XContentMapper {
} }
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
if (field == null) { if (path == null) {
return; return;
} }
builder.startObject(CONTENT_TYPE); builder.startObject(CONTENT_TYPE);
if (field != null) { if (path != null) {
builder.field("field", field); builder.field("path", path);
} }
builder.endObject(); builder.endObject();
} }

View File

@ -216,7 +216,7 @@ public class XContentDocumentMapperParser extends AbstractIndexComponent impleme
for (Map.Entry<String, Object> entry : analyzerNode.entrySet()) { for (Map.Entry<String, Object> entry : analyzerNode.entrySet()) {
String fieldName = Strings.toUnderscoreCase(entry.getKey()); String fieldName = Strings.toUnderscoreCase(entry.getKey());
Object fieldNode = entry.getValue(); Object fieldNode = entry.getValue();
if (fieldName.equals("field")) { if (fieldName.equals("path")) {
builder.field(fieldNode.toString()); builder.field(fieldNode.toString());
} }
} }

View File

@ -37,7 +37,7 @@ public class AnalyzerMapperTests {
@Test public void testLatLonValues() throws Exception { @Test public void testLatLonValues() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_analyzer").field("field", "field_analyzer").endObject() .startObject("_analyzer").field("path", "field_analyzer").endObject()
.startObject("properties") .startObject("properties")
.startObject("field_analyzer").field("type", "string").endObject() .startObject("field_analyzer").field("type", "string").endObject()
.startObject("field1").field("type", "string").endObject() .startObject("field1").field("type", "string").endObject()