add an option to provide the array of ranges "on" the field name itself

This commit is contained in:
kimchy 2010-08-02 16:39:28 +03:00
parent 6ed89ad406
commit 99af6df0ea
1 changed files with 21 additions and 23 deletions

View File

@ -56,32 +56,30 @@ public class RangeFacetCollectorParser implements FacetCollectorParser {
if (token == XContentParser.Token.FIELD_NAME) { if (token == XContentParser.Token.FIELD_NAME) {
fieldName = parser.currentName(); fieldName = parser.currentName();
} else if (token == XContentParser.Token.START_ARRAY) { } else if (token == XContentParser.Token.START_ARRAY) {
if ("ranges".equals(fieldName) || "entries".equals(fieldName)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
// "ranges" : [ RangeFacet.Entry entry = new RangeFacet.Entry();
// { "from" : "0', to : "12.5" } while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
// { "from" : "12.5" } if (token == XContentParser.Token.FIELD_NAME) {
// ] fieldName = parser.currentName();
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { } else if (token == XContentParser.Token.VALUE_STRING) {
RangeFacet.Entry entry = new RangeFacet.Entry(); if ("from".equals(fieldName)) {
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { entry.fromAsString = parser.text();
if (token == XContentParser.Token.FIELD_NAME) { } else if ("to".equals(fieldName)) {
fieldName = parser.currentName(); entry.toAsString = parser.text();
} else if (token == XContentParser.Token.VALUE_STRING) { }
if ("from".equals(fieldName)) { } else if (token.isValue()) {
entry.fromAsString = parser.text(); if ("from".equals(fieldName)) {
} else if ("to".equals(fieldName)) { entry.from = parser.doubleValue();
entry.toAsString = parser.text(); } else if ("to".equals(fieldName)) {
} entry.to = parser.doubleValue();
} else if (token.isValue()) {
if ("from".equals(fieldName)) {
entry.from = parser.doubleValue();
} else if ("to".equals(fieldName)) {
entry.to = parser.doubleValue();
}
} }
} }
entries.add(entry);
} }
entries.add(entry);
}
if (!"ranges".equals(fieldName)) {
// this is the actual field name, so also update the keyField
keyField = fieldName;
} }
} else if (token == XContentParser.Token.START_OBJECT) { } else if (token == XContentParser.Token.START_OBJECT) {
if ("params".equals(fieldName)) { if ("params".equals(fieldName)) {