Skip to content

Commit

Permalink
Cleaner error handling. Pre without post (or vice versa) is not an er…
Browse files Browse the repository at this point in the history
…ror condition. Set appropriate defaults for pre/post.
  • Loading branch information
brusic committed Nov 18, 2014
1 parent 03c4b58 commit f3bd02d
Showing 1 changed file with 8 additions and 6 deletions.
Expand Up @@ -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() {
}
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f3bd02d

Please sign in to comment.