From a1ab48c80429fed4834a33cdf5127fc923dba7e2 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Thu, 9 Aug 2012 13:50:10 +0200 Subject: [PATCH] handle null query returning from query parsers properly now that we support "null" queries, for example, when parsing a query and its lenient, make sure to handle it where applicable --- .../java/org/elasticsearch/index/query/FieldQueryParser.java | 3 +++ .../java/org/elasticsearch/index/query/MatchQueryParser.java | 3 +++ .../org/elasticsearch/index/query/MultiMatchQueryParser.java | 3 +++ .../org/elasticsearch/index/query/QueryStringQueryParser.java | 3 +++ 4 files changed, 12 insertions(+) diff --git a/src/main/java/org/elasticsearch/index/query/FieldQueryParser.java b/src/main/java/org/elasticsearch/index/query/FieldQueryParser.java index 820a0d4f34a..88f86fc5d5e 100644 --- a/src/main/java/org/elasticsearch/index/query/FieldQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/FieldQueryParser.java @@ -166,6 +166,9 @@ public class FieldQueryParser implements QueryParser { try { query = queryParser.parse(qpSettings.queryString()); + if (query == null) { + return null; + } query.setBoost(qpSettings.boost()); query = optimizeQuery(fixNegativeQueryIfNeeded(query)); if (query instanceof BooleanQuery) { diff --git a/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java b/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java index b46bbb50fbd..c2bf9674b10 100644 --- a/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java @@ -139,6 +139,9 @@ public class MatchQueryParser implements QueryParser { } Query query = matchQuery.parse(type, fieldName, text); + if (query == null) { + return null; + } if (query instanceof BooleanQuery) { Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch); diff --git a/src/main/java/org/elasticsearch/index/query/MultiMatchQueryParser.java b/src/main/java/org/elasticsearch/index/query/MultiMatchQueryParser.java index 7d620f90b97..282ee16a568 100644 --- a/src/main/java/org/elasticsearch/index/query/MultiMatchQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/MultiMatchQueryParser.java @@ -169,6 +169,9 @@ public class MultiMatchQueryParser implements QueryParser { } Query query = multiMatchQuery.parse(type, fieldNames, text); + if (query == null) { + return null; + } if (query instanceof BooleanQuery) { Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch); diff --git a/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java b/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java index 3069d86da0c..9600090c2a4 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java @@ -210,6 +210,9 @@ public class QueryStringQueryParser implements QueryParser { try { query = queryParser.parse(qpSettings.queryString()); + if (query == null) { + return null; + } query.setBoost(qpSettings.boost()); query = optimizeQuery(fixNegativeQueryIfNeeded(query)); if (query instanceof BooleanQuery) {