From 63eb81e7afed7c0f60b6706f4abaf63e1178f9e3 Mon Sep 17 00:00:00 2001 From: Isabel Drost-Fromm Date: Wed, 27 Apr 2016 13:19:50 +0200 Subject: [PATCH 1/4] Switches from empty boolean query to matchNoDocs Closes #17981 --- .../common/lucene/search/Queries.java | 3 +- .../index/search/MatchQuery.java | 2 + .../index/query/IdsQueryBuilderTests.java | 4 +- .../query/MatchNoneQueryBuilderTests.java | 7 +- .../MatchPhrasePrefixQueryBuilderTests.java | 3 +- .../query/MatchPhraseQueryBuilderTests.java | 3 +- .../index/query/MatchQueryBuilderTests.java | 3 +- .../index/query/TermsQueryBuilderTests.java | 69 ++++++++++--------- 8 files changed, 51 insertions(+), 43 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/lucene/search/Queries.java b/core/src/main/java/org/elasticsearch/common/lucene/search/Queries.java index 53ee2295ae4..42663b11ce4 100644 --- a/core/src/main/java/org/elasticsearch/common/lucene/search/Queries.java +++ b/core/src/main/java/org/elasticsearch/common/lucene/search/Queries.java @@ -25,6 +25,7 @@ import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.ConstantScoreQuery; import org.apache.lucene.search.MatchAllDocsQuery; +import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.PrefixQuery; import org.apache.lucene.search.Query; import org.apache.lucene.util.BytesRef; @@ -45,7 +46,7 @@ public class Queries { /** Return a query that matches no document. */ public static Query newMatchNoDocsQuery() { - return new BooleanQuery.Builder().build(); + return new MatchNoDocsQuery(); } public static Query newNestedFilter() { diff --git a/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java b/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java index 14b6e120fb7..a8b0b55bd30 100644 --- a/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java +++ b/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java @@ -286,6 +286,8 @@ public class MatchQuery { } protected Query zeroTermsQuery() { + // TODO This is weird: DEFAULT_ZERO_TERMS_QUERY is a public static final field, so this can have only one value. + // why are we then having this if clause in here? return zeroTermsQuery == DEFAULT_ZERO_TERMS_QUERY ? Queries.newMatchNoDocsQuery() : Queries.newMatchAllQuery(); } diff --git a/core/src/test/java/org/elasticsearch/index/query/IdsQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/IdsQueryBuilderTests.java index 2fe7d3cfc0c..894f49eb849 100644 --- a/core/src/test/java/org/elasticsearch/index/query/IdsQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/IdsQueryBuilderTests.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.query; import org.apache.lucene.queries.TermsQuery; import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.ParsingException; @@ -88,8 +89,7 @@ public class IdsQueryBuilderTests extends AbstractQueryTestCase @Override protected void doAssertLuceneQuery(IdsQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { if (queryBuilder.ids().size() == 0) { - assertThat(query, instanceOf(BooleanQuery.class)); - assertThat(((BooleanQuery)query).clauses().size(), equalTo(0)); + assertThat(query, instanceOf(MatchNoDocsQuery.class)); } else { assertThat(query, instanceOf(TermsQuery.class)); } diff --git a/core/src/test/java/org/elasticsearch/index/query/MatchNoneQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/MatchNoneQueryBuilderTests.java index 066db1aad45..7c0564697d0 100644 --- a/core/src/test/java/org/elasticsearch/index/query/MatchNoneQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/MatchNoneQueryBuilderTests.java @@ -19,12 +19,11 @@ package org.elasticsearch.index.query; -import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; import java.io.IOException; -import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; public class MatchNoneQueryBuilderTests extends AbstractQueryTestCase { @@ -36,9 +35,7 @@ public class MatchNoneQueryBuilderTests extends AbstractQueryTestCase terms; - if (queryBuilder.termsLookup() != null) { - terms = randomTerms; + if (queryBuilder.termsLookup() == null && (queryBuilder.values() == null || queryBuilder.values().isEmpty())) { + assertThat(query, instanceOf(MatchNoDocsQuery.class)); } else { - terms = queryBuilder.values(); - } - - // compare whether we have the expected list of terms returned - final List booleanTerms = new ArrayList<>(); - for (BooleanClause booleanClause : booleanQuery) { - assertThat(booleanClause.getOccur(), equalTo(BooleanClause.Occur.SHOULD)); - assertThat(booleanClause.getQuery(), instanceOf(TermQuery.class)); - Term term = ((TermQuery) booleanClause.getQuery()).getTerm(); - booleanTerms.add(term); - } - CollectionUtil.timSort(booleanTerms); - List expectedTerms = new ArrayList<>(); - for (Object term : terms) { - if (term != null) { // terms lookup filters this out - expectedTerms.add(new Term(queryBuilder.fieldName(), term.toString())); + assertThat(query, instanceOf(BooleanQuery.class)); + BooleanQuery booleanQuery = (BooleanQuery) query; + + // we only do the check below for string fields (otherwise we'd have to decode the values) + if (queryBuilder.fieldName().equals(INT_FIELD_NAME) || queryBuilder.fieldName().equals(DOUBLE_FIELD_NAME) + || queryBuilder.fieldName().equals(BOOLEAN_FIELD_NAME) || queryBuilder.fieldName().equals(DATE_FIELD_NAME)) { + return; } + + // expected returned terms depending on whether we have a terms query or a terms lookup query + List terms; + if (queryBuilder.termsLookup() != null) { + terms = randomTerms; + } else { + terms = queryBuilder.values(); + } + + // compare whether we have the expected list of terms returned + final List booleanTerms = new ArrayList<>(); + for (BooleanClause booleanClause : booleanQuery) { + assertThat(booleanClause.getOccur(), equalTo(BooleanClause.Occur.SHOULD)); + assertThat(booleanClause.getQuery(), instanceOf(TermQuery.class)); + Term term = ((TermQuery) booleanClause.getQuery()).getTerm(); + booleanTerms.add(term); + } + CollectionUtil.timSort(booleanTerms); + List expectedTerms = new ArrayList<>(); + for (Object term : terms) { + if (term != null) { // terms lookup filters this out + expectedTerms.add(new Term(queryBuilder.fieldName(), term.toString())); + } + } + CollectionUtil.timSort(expectedTerms); + assertEquals(expectedTerms + " vs. " + booleanTerms, expectedTerms.size(), booleanTerms.size()); + assertEquals(expectedTerms + " vs. " + booleanTerms, expectedTerms, booleanTerms); } - CollectionUtil.timSort(expectedTerms); - assertEquals(expectedTerms + " vs. " + booleanTerms, expectedTerms.size(), booleanTerms.size()); - assertEquals(expectedTerms + " vs. " + booleanTerms, expectedTerms, booleanTerms); } public void testEmtpyFieldName() { From 4c9070c52e64c37571f2e497c9d1ee1ab11449cd Mon Sep 17 00:00:00 2001 From: Isabel Drost-Fromm Date: Wed, 27 Apr 2016 14:03:29 +0200 Subject: [PATCH 2/4] Removing question concerning default no docs query. --- .../main/java/org/elasticsearch/index/search/MatchQuery.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java b/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java index a8b0b55bd30..14b6e120fb7 100644 --- a/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java +++ b/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java @@ -286,8 +286,6 @@ public class MatchQuery { } protected Query zeroTermsQuery() { - // TODO This is weird: DEFAULT_ZERO_TERMS_QUERY is a public static final field, so this can have only one value. - // why are we then having this if clause in here? return zeroTermsQuery == DEFAULT_ZERO_TERMS_QUERY ? Queries.newMatchNoDocsQuery() : Queries.newMatchAllQuery(); } From 6f8932a0448f2c1fb3a00a8a5949f51b7c4bcf15 Mon Sep 17 00:00:00 2001 From: Isabel Drost-Fromm Date: Wed, 27 Apr 2016 14:30:19 +0200 Subject: [PATCH 3/4] Switch to MatchNoDocsQuery with explicit reason string --- .../common/lucene/search/MultiPhrasePrefixQuery.java | 2 +- .../org/elasticsearch/common/lucene/search/Queries.java | 5 ++--- .../index/mapper/internal/IndexFieldMapper.java | 4 ++-- .../org/elasticsearch/index/query/ExistsQueryBuilder.java | 2 +- .../java/org/elasticsearch/index/query/IdsQueryBuilder.java | 2 +- .../elasticsearch/index/query/MatchNoneQueryBuilder.java | 2 +- .../org/elasticsearch/index/query/QueryShardContext.java | 2 +- .../org/elasticsearch/index/query/TermsQueryBuilder.java | 2 +- .../java/org/elasticsearch/index/search/MatchQuery.java | 6 +++++- .../elasticsearch/index/query/AbstractQueryTestCase.java | 1 - .../org/elasticsearch/index/query/IdsQueryBuilderTests.java | 4 +--- .../index/query/MatchNoneQueryBuilderTests.java | 2 +- .../index/query/MatchPhrasePrefixQueryBuilderTests.java | 2 +- .../index/query/MatchPhraseQueryBuilderTests.java | 2 +- .../elasticsearch/index/query/MatchQueryBuilderTests.java | 3 +-- .../index/query/MultiMatchQueryBuilderTests.java | 2 +- .../elasticsearch/index/query/TermsQueryBuilderTests.java | 2 +- 17 files changed, 22 insertions(+), 23 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/lucene/search/MultiPhrasePrefixQuery.java b/core/src/main/java/org/elasticsearch/common/lucene/search/MultiPhrasePrefixQuery.java index 52de9a7e5db..05006ec0db7 100644 --- a/core/src/main/java/org/elasticsearch/common/lucene/search/MultiPhrasePrefixQuery.java +++ b/core/src/main/java/org/elasticsearch/common/lucene/search/MultiPhrasePrefixQuery.java @@ -150,7 +150,7 @@ public class MultiPhrasePrefixQuery extends Query { } } if (terms.isEmpty()) { - return Queries.newMatchNoDocsQuery(); + return Queries.newMatchNoDocsQuery("No terms supplied for " + MultiPhrasePrefixQuery.class.getName()); } query.add(terms.toArray(Term.class), position); return query.build(); diff --git a/core/src/main/java/org/elasticsearch/common/lucene/search/Queries.java b/core/src/main/java/org/elasticsearch/common/lucene/search/Queries.java index 42663b11ce4..c3144a7e372 100644 --- a/core/src/main/java/org/elasticsearch/common/lucene/search/Queries.java +++ b/core/src/main/java/org/elasticsearch/common/lucene/search/Queries.java @@ -25,7 +25,6 @@ import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.ConstantScoreQuery; import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.PrefixQuery; import org.apache.lucene.search.Query; import org.apache.lucene.util.BytesRef; @@ -45,8 +44,8 @@ public class Queries { } /** Return a query that matches no document. */ - public static Query newMatchNoDocsQuery() { - return new MatchNoDocsQuery(); + public static Query newMatchNoDocsQuery(String reason) { + return new MatchNoDocsQuery(reason); } public static Query newNestedFilter() { diff --git a/core/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java index 47b6047d220..5dc1d577f0e 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java @@ -138,7 +138,7 @@ public class IndexFieldMapper extends MetadataFieldMapper { if (isSameIndex(value, context.index().getName())) { return Queries.newMatchAllQuery(); } else { - return Queries.newMatchNoDocsQuery(); + return Queries.newMatchNoDocsQuery("Index didn't match. Index queried: " + context.index().getName() + " vs. " + value); } } @@ -157,7 +157,7 @@ public class IndexFieldMapper extends MetadataFieldMapper { } } // None of the listed index names are this one - return Queries.newMatchNoDocsQuery(); + return Queries.newMatchNoDocsQuery("Index didn't match. Index queried: " + context.index().getName() + " vs. " + values); } private boolean isSameIndex(Object value, String indexName) { diff --git a/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java index dec6baf067c..cd7a3dbb93c 100644 --- a/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java @@ -134,7 +134,7 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder (FieldNamesFieldMapper.FieldNamesFieldType)context.getMapperService().fullName(FieldNamesFieldMapper.NAME); if (fieldNamesFieldType == null) { // can only happen when no types exist, so no docs exist either - return Queries.newMatchNoDocsQuery(); + return Queries.newMatchNoDocsQuery("Missing types in " + NAME); } final Collection fields; diff --git a/core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java index e8f1fb93b74..e712ab47073 100644 --- a/core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java @@ -204,7 +204,7 @@ public class IdsQueryBuilder extends AbstractQueryBuilder { protected Query doToQuery(QueryShardContext context) throws IOException { Query query; if (this.ids.isEmpty()) { - query = Queries.newMatchNoDocsQuery(); + query = Queries.newMatchNoDocsQuery("Missing ids in " + this.getName()); } else { Collection typesForQuery; if (types.length == 0) { diff --git a/core/src/main/java/org/elasticsearch/index/query/MatchNoneQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/MatchNoneQueryBuilder.java index d17d8515bb8..aca98191825 100644 --- a/core/src/main/java/org/elasticsearch/index/query/MatchNoneQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/MatchNoneQueryBuilder.java @@ -93,7 +93,7 @@ public class MatchNoneQueryBuilder extends AbstractQueryBuilder queryBuilder, final QueryShardContext context) throws IOException { final Query query = QueryBuilder.rewriteQuery(queryBuilder, context).toQuery(context); if (query == null) { - return Queries.newMatchNoDocsQuery(); + return Queries.newMatchNoDocsQuery("No query left after rewrite."); } return query; } diff --git a/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java index 19fe8da3011..028f365d70e 100644 --- a/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java @@ -317,7 +317,7 @@ public class TermsQueryBuilder extends AbstractQueryBuilder { throw new UnsupportedOperationException("query must be rewritten first"); } if (values == null || values.isEmpty()) { - return Queries.newMatchNoDocsQuery(); + return Queries.newMatchNoDocsQuery("No terms supplied for " + getName()); } return handleTermsQuery(values, fieldName, context); } diff --git a/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java b/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java index 14b6e120fb7..152300e6e14 100644 --- a/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java +++ b/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java @@ -286,7 +286,11 @@ public class MatchQuery { } protected Query zeroTermsQuery() { - return zeroTermsQuery == DEFAULT_ZERO_TERMS_QUERY ? Queries.newMatchNoDocsQuery() : Queries.newMatchAllQuery(); + if (zeroTermsQuery == DEFAULT_ZERO_TERMS_QUERY) { + return Queries.newMatchNoDocsQuery("No query supplied in match query"); + } + + return Queries.newMatchAllQuery(); } private class MatchQueryBuilder extends QueryBuilder { diff --git a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java index a3004ba896c..ba55413a27b 100644 --- a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java @@ -24,7 +24,6 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.io.JsonStringEncoder; import org.apache.lucene.search.BoostQuery; -import org.apache.lucene.search.PrefixQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.spans.SpanBoostQuery; diff --git a/core/src/test/java/org/elasticsearch/index/query/IdsQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/IdsQueryBuilderTests.java index 894f49eb849..c7cfa4e0e1d 100644 --- a/core/src/test/java/org/elasticsearch/index/query/IdsQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/IdsQueryBuilderTests.java @@ -21,17 +21,15 @@ package org.elasticsearch.index.query; import org.apache.lucene.queries.TermsQuery; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.ParsingException; +import org.elasticsearch.common.lucene.search.MatchNoDocsQuery; import java.io.IOException; import java.util.HashMap; import java.util.Map; -import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; diff --git a/core/src/test/java/org/elasticsearch/index/query/MatchNoneQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/MatchNoneQueryBuilderTests.java index 7c0564697d0..e2ebbd8864d 100644 --- a/core/src/test/java/org/elasticsearch/index/query/MatchNoneQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/MatchNoneQueryBuilderTests.java @@ -19,8 +19,8 @@ package org.elasticsearch.index.query; -import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; +import org.elasticsearch.common.lucene.search.MatchNoDocsQuery; import java.io.IOException; diff --git a/core/src/test/java/org/elasticsearch/index/query/MatchPhrasePrefixQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/MatchPhrasePrefixQueryBuilderTests.java index 1d719e29b62..bb6f332c901 100644 --- a/core/src/test/java/org/elasticsearch/index/query/MatchPhrasePrefixQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/MatchPhrasePrefixQueryBuilderTests.java @@ -20,10 +20,10 @@ package org.elasticsearch.index.query; import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.PointRangeQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; +import org.elasticsearch.common.lucene.search.MatchNoDocsQuery; import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery; import java.io.IOException; import static org.hamcrest.CoreMatchers.either; diff --git a/core/src/test/java/org/elasticsearch/index/query/MatchPhraseQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/MatchPhraseQueryBuilderTests.java index d19e3848060..dc5a8d58389 100644 --- a/core/src/test/java/org/elasticsearch/index/query/MatchPhraseQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/MatchPhraseQueryBuilderTests.java @@ -20,11 +20,11 @@ package org.elasticsearch.index.query; import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.PointRangeQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; +import org.elasticsearch.common.lucene.search.MatchNoDocsQuery; import java.io.IOException; diff --git a/core/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java index a8d42d6c69e..543a5ea08c3 100644 --- a/core/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java @@ -25,13 +25,12 @@ import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.LegacyNumericRangeQuery; import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.PointRangeQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.Strings; +import org.elasticsearch.common.lucene.search.MatchNoDocsQuery; import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.unit.Fuzziness; diff --git a/core/src/test/java/org/elasticsearch/index/query/MultiMatchQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/MultiMatchQueryBuilderTests.java index f82a2844f25..f4baaa4880c 100644 --- a/core/src/test/java/org/elasticsearch/index/query/MultiMatchQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/MultiMatchQueryBuilderTests.java @@ -27,12 +27,12 @@ import org.apache.lucene.search.DisjunctionMaxQuery; import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.LegacyNumericRangeQuery; import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.PointRangeQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; import org.elasticsearch.common.lucene.all.AllTermQuery; +import org.elasticsearch.common.lucene.search.MatchNoDocsQuery; import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery; import org.elasticsearch.index.search.MatchQuery; diff --git a/core/src/test/java/org/elasticsearch/index/query/TermsQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/TermsQueryBuilderTests.java index 2b574005410..baf7a1e528c 100644 --- a/core/src/test/java/org/elasticsearch/index/query/TermsQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/TermsQueryBuilderTests.java @@ -22,7 +22,6 @@ package org.elasticsearch.index.query; import org.apache.lucene.index.Term; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; import org.apache.lucene.util.CollectionUtil; @@ -32,6 +31,7 @@ import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.lucene.search.MatchNoDocsQuery; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.get.GetResult; From 7bcc079d6078de417b3e0e2cdd0eb7468aa1834f Mon Sep 17 00:00:00 2001 From: Isabel Drost-Fromm Date: Thu, 28 Apr 2016 12:39:16 +0200 Subject: [PATCH 4/4] Adjust wording according to review. --- .../java/org/elasticsearch/index/query/ExistsQueryBuilder.java | 2 +- .../java/org/elasticsearch/index/query/IdsQueryBuilder.java | 2 +- .../org/elasticsearch/index/query/MatchNoneQueryBuilder.java | 2 +- .../java/org/elasticsearch/index/query/TermsQueryBuilder.java | 2 +- .../main/java/org/elasticsearch/index/search/MatchQuery.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java index cd7a3dbb93c..afcff164bec 100644 --- a/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java @@ -134,7 +134,7 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder (FieldNamesFieldMapper.FieldNamesFieldType)context.getMapperService().fullName(FieldNamesFieldMapper.NAME); if (fieldNamesFieldType == null) { // can only happen when no types exist, so no docs exist either - return Queries.newMatchNoDocsQuery("Missing types in " + NAME); + return Queries.newMatchNoDocsQuery("Missing types in \"" + NAME + "\" query."); } final Collection fields; diff --git a/core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java index e712ab47073..7845e2732ea 100644 --- a/core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java @@ -204,7 +204,7 @@ public class IdsQueryBuilder extends AbstractQueryBuilder { protected Query doToQuery(QueryShardContext context) throws IOException { Query query; if (this.ids.isEmpty()) { - query = Queries.newMatchNoDocsQuery("Missing ids in " + this.getName()); + query = Queries.newMatchNoDocsQuery("Missing ids in \"" + this.getName() + "\" query."); } else { Collection typesForQuery; if (types.length == 0) { diff --git a/core/src/main/java/org/elasticsearch/index/query/MatchNoneQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/MatchNoneQueryBuilder.java index aca98191825..068b0e86d8e 100644 --- a/core/src/main/java/org/elasticsearch/index/query/MatchNoneQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/MatchNoneQueryBuilder.java @@ -93,7 +93,7 @@ public class MatchNoneQueryBuilder extends AbstractQueryBuilder { throw new UnsupportedOperationException("query must be rewritten first"); } if (values == null || values.isEmpty()) { - return Queries.newMatchNoDocsQuery("No terms supplied for " + getName()); + return Queries.newMatchNoDocsQuery("No terms supplied for \"" + getName() + "\" query."); } return handleTermsQuery(values, fieldName, context); } diff --git a/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java b/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java index 152300e6e14..0fbc17e3ae8 100644 --- a/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java +++ b/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java @@ -287,7 +287,7 @@ public class MatchQuery { protected Query zeroTermsQuery() { if (zeroTermsQuery == DEFAULT_ZERO_TERMS_QUERY) { - return Queries.newMatchNoDocsQuery("No query supplied in match query"); + return Queries.newMatchNoDocsQuery("Matching no documents because no terms present."); } return Queries.newMatchAllQuery();