|
@@ -19,9 +19,11 @@
|
|
|
|
|
|
package org.elasticsearch.index.query;
|
|
|
|
|
|
+import org.apache.lucene.index.Term;
|
|
|
import org.apache.lucene.index.memory.MemoryIndex;
|
|
|
import org.apache.lucene.search.MatchAllDocsQuery;
|
|
|
import org.apache.lucene.search.Query;
|
|
|
+import org.apache.lucene.search.TermQuery;
|
|
|
import org.elasticsearch.action.support.ToXContentToBytes;
|
|
|
import org.elasticsearch.common.ParsingException;
|
|
|
import org.elasticsearch.common.bytes.BytesArray;
|
|
@@ -129,6 +131,24 @@ public class WrapperQueryBuilderTests extends AbstractQueryTestCase<WrapperQuery
|
|
|
assertEquals(new BoolQueryBuilder().must(query).boost(3), builder.rewrite(shardContext));
|
|
|
}
|
|
|
|
|
|
+ public void testRewriteInnerQueryToo() throws IOException {
|
|
|
+ QueryShardContext shardContext = createShardContext();
|
|
|
+
|
|
|
+ QueryBuilder qb = new WrapperQueryBuilder(
|
|
|
+ new WrapperQueryBuilder(new TermQueryBuilder("foo", "bar").toString()).toString()
|
|
|
+ );
|
|
|
+ assertEquals(new TermQuery(new Term("foo", "bar")), qb.rewrite(shardContext).toQuery(shardContext));
|
|
|
+ qb = new WrapperQueryBuilder(
|
|
|
+ new WrapperQueryBuilder(
|
|
|
+ new WrapperQueryBuilder(new TermQueryBuilder("foo", "bar").toString()).toString()
|
|
|
+ ).toString()
|
|
|
+ );
|
|
|
+ assertEquals(new TermQuery(new Term("foo", "bar")), qb.rewrite(shardContext).toQuery(shardContext));
|
|
|
+
|
|
|
+ qb = new WrapperQueryBuilder(new BoolQueryBuilder().toString());
|
|
|
+ assertEquals(new MatchAllDocsQuery(), qb.rewrite(shardContext).toQuery(shardContext));
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
protected Query rewrite(Query query) throws IOException {
|
|
|
// WrapperQueryBuilder adds some optimization if the wrapper and query builder have boosts / query names that wraps
|