Skip to content

Commit f3bd02d

Browse files
committed
Cleaner error handling. Pre without post (or vice versa) is not an error condition. Set appropriate defaults for pre/post.
1 parent 03c4b58 commit f3bd02d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/main/java/org/elasticsearch/index/query/SpanNotQueryParser.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class SpanNotQueryParser implements QueryParser {
3535

3636
public static final String NAME = "span_not";
3737

38+
public static final int NOT_SET = -1;
39+
3840
@Inject
3941
public SpanNotQueryParser() {
4042
}
@@ -53,9 +55,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
5355
SpanQuery include = null;
5456
SpanQuery exclude = null;
5557

56-
int dist = -1;
57-
int pre = -1;
58-
int post = -1;
58+
int dist = NOT_SET;
59+
int pre = NOT_SET;
60+
int post = NOT_SET;
5961

6062
String queryName = null;
6163

@@ -102,14 +104,14 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
102104
if (exclude == null) {
103105
throw new QueryParsingException(parseContext.index(), "spanNot must have [exclude] span query clause");
104106
}
105-
if ((dist != -1 && (pre != -1 || post != -1)) || (pre != -1 && post == -1) || (pre == -1 && post != -1)) {
107+
if (dist != NOT_SET && (pre != NOT_SET || post != NOT_SET)) {
106108
throw new QueryParsingException(parseContext.index(), "spanNot can either use [dist] or [pre] & [post] (or none)");
107109
}
108110

109111
SpanNotQuery query;
110-
if (pre != -1 && post != -1) {
112+
if (pre != NOT_SET && post != NOT_SET) {
111113
query = new SpanNotQuery(include, exclude, pre, post);
112-
} else if (dist != -1) {
114+
} else if (dist != NOT_SET) {
113115
query = new SpanNotQuery(include, exclude, dist);
114116
} else {
115117
query = new SpanNotQuery(include, exclude);

0 commit comments

Comments
 (0)