Cleaner error handling. Pre without post (or vice versa) is not an error condition. Set appropriate defaults for pre/post.

This commit is contained in:
Brusic 2014-03-16 10:25:50 -07:00 committed by Martijn van Groningen
parent 94074b4028
commit 5a001e1357
1 changed files with 8 additions and 6 deletions

View File

@ -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 class SpanNotQueryParser implements QueryParser {
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 class SpanNotQueryParser implements QueryParser {
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);