From 99af6df0ea9083495d1620ef588cc0b655c0812d Mon Sep 17 00:00:00 2001 From: kimchy Date: Mon, 2 Aug 2010 16:39:28 +0300 Subject: [PATCH] add an option to provide the array of ranges "on" the field name itself --- .../range/RangeFacetCollectorParser.java | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/range/RangeFacetCollectorParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/range/RangeFacetCollectorParser.java index 72a0f093fd3..afd930fc9be 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/range/RangeFacetCollectorParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/range/RangeFacetCollectorParser.java @@ -56,32 +56,30 @@ public class RangeFacetCollectorParser implements FacetCollectorParser { if (token == XContentParser.Token.FIELD_NAME) { fieldName = parser.currentName(); } else if (token == XContentParser.Token.START_ARRAY) { - if ("ranges".equals(fieldName) || "entries".equals(fieldName)) { - // "ranges" : [ - // { "from" : "0', to : "12.5" } - // { "from" : "12.5" } - // ] - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - RangeFacet.Entry entry = new RangeFacet.Entry(); - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - fieldName = parser.currentName(); - } else if (token == XContentParser.Token.VALUE_STRING) { - if ("from".equals(fieldName)) { - entry.fromAsString = parser.text(); - } else if ("to".equals(fieldName)) { - entry.toAsString = parser.text(); - } - } else if (token.isValue()) { - if ("from".equals(fieldName)) { - entry.from = parser.doubleValue(); - } else if ("to".equals(fieldName)) { - entry.to = parser.doubleValue(); - } + while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { + RangeFacet.Entry entry = new RangeFacet.Entry(); + while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { + if (token == XContentParser.Token.FIELD_NAME) { + fieldName = parser.currentName(); + } else if (token == XContentParser.Token.VALUE_STRING) { + if ("from".equals(fieldName)) { + entry.fromAsString = parser.text(); + } else if ("to".equals(fieldName)) { + entry.toAsString = parser.text(); + } + } 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) { if ("params".equals(fieldName)) {