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:
parent
94074b4028
commit
5a001e1357
|
@ -35,6 +35,8 @@ public class SpanNotQueryParser implements QueryParser {
|
||||||
|
|
||||||
public static final String NAME = "span_not";
|
public static final String NAME = "span_not";
|
||||||
|
|
||||||
|
public static final int NOT_SET = -1;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public SpanNotQueryParser() {
|
public SpanNotQueryParser() {
|
||||||
}
|
}
|
||||||
|
@ -53,9 +55,9 @@ public class SpanNotQueryParser implements QueryParser {
|
||||||
SpanQuery include = null;
|
SpanQuery include = null;
|
||||||
SpanQuery exclude = null;
|
SpanQuery exclude = null;
|
||||||
|
|
||||||
int dist = -1;
|
int dist = NOT_SET;
|
||||||
int pre = -1;
|
int pre = NOT_SET;
|
||||||
int post = -1;
|
int post = NOT_SET;
|
||||||
|
|
||||||
String queryName = null;
|
String queryName = null;
|
||||||
|
|
||||||
|
@ -102,14 +104,14 @@ public class SpanNotQueryParser implements QueryParser {
|
||||||
if (exclude == null) {
|
if (exclude == null) {
|
||||||
throw new QueryParsingException(parseContext.index(), "spanNot must have [exclude] span query clause");
|
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)");
|
throw new QueryParsingException(parseContext.index(), "spanNot can either use [dist] or [pre] & [post] (or none)");
|
||||||
}
|
}
|
||||||
|
|
||||||
SpanNotQuery query;
|
SpanNotQuery query;
|
||||||
if (pre != -1 && post != -1) {
|
if (pre != NOT_SET && post != NOT_SET) {
|
||||||
query = new SpanNotQuery(include, exclude, pre, post);
|
query = new SpanNotQuery(include, exclude, pre, post);
|
||||||
} else if (dist != -1) {
|
} else if (dist != NOT_SET) {
|
||||||
query = new SpanNotQuery(include, exclude, dist);
|
query = new SpanNotQuery(include, exclude, dist);
|
||||||
} else {
|
} else {
|
||||||
query = new SpanNotQuery(include, exclude);
|
query = new SpanNotQuery(include, exclude);
|
||||||
|
|
Loading…
Reference in New Issue