|
|
@@ -0,0 +1,64 @@
|
|
|
+/*
|
|
|
+ * Licensed to Elasticsearch under one or more contributor
|
|
|
+ * license agreements. See the NOTICE file distributed with
|
|
|
+ * this work for additional information regarding copyright
|
|
|
+ * ownership. Elasticsearch licenses this file to you under
|
|
|
+ * the Apache License, Version 2.0 (the "License"); you may
|
|
|
+ * not use this file except in compliance with the License.
|
|
|
+ * You may obtain a copy of the License at
|
|
|
+ *
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
+ *
|
|
|
+ * Unless required by applicable law or agreed to in writing,
|
|
|
+ * software distributed under the License is distributed on an
|
|
|
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
+ * KIND, either express or implied. See the License for the
|
|
|
+ * specific language governing permissions and limitations
|
|
|
+ * under the License.
|
|
|
+ */
|
|
|
+
|
|
|
+package org.elasticsearch.index.search.child;
|
|
|
+
|
|
|
+import org.apache.lucene.index.Term;
|
|
|
+import org.apache.lucene.search.Query;
|
|
|
+import org.apache.lucene.search.QueryUtils;
|
|
|
+import org.apache.lucene.search.TermQuery;
|
|
|
+import org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData;
|
|
|
+import org.elasticsearch.index.mapper.internal.ParentFieldMapper;
|
|
|
+import org.elasticsearch.index.search.nested.NonNestedDocsFilter;
|
|
|
+import org.elasticsearch.search.internal.SearchContext;
|
|
|
+import org.elasticsearch.test.ElasticsearchLuceneTestCase;
|
|
|
+import org.junit.AfterClass;
|
|
|
+import org.junit.BeforeClass;
|
|
|
+import org.junit.Test;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
+import static org.elasticsearch.index.search.child.ChildrenConstantScoreQueryTests.createSearchContext;
|
|
|
+
|
|
|
+/**
|
|
|
+ */
|
|
|
+public class TopChildrenQueryTests extends ElasticsearchLuceneTestCase {
|
|
|
+
|
|
|
+ @BeforeClass
|
|
|
+ public static void before() throws IOException {
|
|
|
+ forceDefaultCodec();
|
|
|
+ SearchContext.setCurrent(createSearchContext("test", "parent", "child"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @AfterClass
|
|
|
+ public static void after() throws IOException {
|
|
|
+ SearchContext.removeCurrent();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testBasicQuerySanities() {
|
|
|
+ Query childQuery = new TermQuery(new Term("field", "value"));
|
|
|
+ ScoreType scoreType = ScoreType.values()[random().nextInt(ScoreType.values().length)];
|
|
|
+ ParentFieldMapper parentFieldMapper = SearchContext.current().mapperService().documentMapper("child").parentFieldMapper();
|
|
|
+ ParentChildIndexFieldData parentChildIndexFieldData = SearchContext.current().fieldData().getForField(parentFieldMapper);
|
|
|
+ Query query = new TopChildrenQuery(parentChildIndexFieldData, childQuery, "child", "parent", scoreType, 1, 1, SearchContext.current().cacheRecycler(), NonNestedDocsFilter.INSTANCE);
|
|
|
+ QueryUtils.check(query);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|