From f3bd02d17db67abe405cc04c838cd5781523b683 Mon Sep 17 00:00:00 2001 From: Brusic Date: Sun, 16 Mar 2014 10:25:50 -0700 Subject: [PATCH] Cleaner error handling. Pre without post (or vice versa) is not an error condition. Set appropriate defaults for pre/post. --- .../index/query/SpanNotQueryParser.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/query/SpanNotQueryParser.java b/src/main/java/org/elasticsearch/index/query/SpanNotQueryParser.java index 5deb945d45802..b099db72cb4cc 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanNotQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/SpanNotQueryParser.java @@ -35,6 +35,8 @@ public class SpanNotQueryParser implements QueryParser { public static final String NAME = "span_not"; + public static final int NOT_SET = -1; + @Inject public SpanNotQueryParser() { } @@ -53,9 +55,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars SpanQuery include = null; SpanQuery exclude = null; - int dist = -1; - int pre = -1; - int post = -1; + int dist = NOT_SET; + int pre = NOT_SET; + int post = NOT_SET; String queryName = null; @@ -102,14 +104,14 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars if (exclude == null) { throw new QueryParsingException(parseContext.index(), "spanNot must have [exclude] span query clause"); } - if ((dist != -1 && (pre != -1 || post != -1)) || (pre != -1 && post == -1) || (pre == -1 && post != -1)) { + if (dist != NOT_SET && (pre != NOT_SET || post != NOT_SET)) { throw new QueryParsingException(parseContext.index(), "spanNot can either use [dist] or [pre] & [post] (or none)"); } SpanNotQuery query; - if (pre != -1 && post != -1) { + if (pre != NOT_SET && post != NOT_SET) { query = new SpanNotQuery(include, exclude, pre, post); - } else if (dist != -1) { + } else if (dist != NOT_SET) { query = new SpanNotQuery(include, exclude, dist); } else { query = new SpanNotQuery(include, exclude);