You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mk...@apache.org on 2019/08/29 14:38:08 UTC

[lucene-solr] branch master updated: SOLR-13720: BlockJoinParentQParser.getCachedFilter made public

This is an automated email from the ASF dual-hosted git repository.

mkhl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new 6dea678  SOLR-13720: BlockJoinParentQParser.getCachedFilter made public
6dea678 is described below

commit 6dea6784396ca3a91524671789da6a36fbf32b54
Author: Mikhail Khludnev <mk...@apache.org>
AuthorDate: Thu Aug 29 17:36:48 2019 +0300

    SOLR-13720: BlockJoinParentQParser.getCachedFilter made public
---
 solr/CHANGES.txt                                   |  3 ++
 .../solr/search/join/BlockJoinChildQParser.java    |  2 +-
 .../solr/search/join/BlockJoinParentQParser.java   | 13 +++---
 .../search/join/ChildFieldValueSourceParser.java   |  4 +-
 .../join/another/BJQFilterAccessibleTest.java      | 52 ++++++++++++++++++++++
 5 files changed, 66 insertions(+), 8 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 7bef392..dad7a1c 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -146,6 +146,9 @@ Improvements
 
 * SOLR-13542: Code cleanup - Avoid using stream filter count where possible (Koen De Groote via Tomás Fernández Löbbe)
 
+* SOLR-13720: BlockJoinParentQParser.getCachedFilter()made public for accessing from QParser plugins
+  (Stanislav Livotov via Mikhail Khludnev) 
+
 Bug Fixes
 ----------------------
 
diff --git a/solr/core/src/java/org/apache/solr/search/join/BlockJoinChildQParser.java b/solr/core/src/java/org/apache/solr/search/join/BlockJoinChildQParser.java
index 0c5c4e8..2c005ac 100644
--- a/solr/core/src/java/org/apache/solr/search/join/BlockJoinChildQParser.java
+++ b/solr/core/src/java/org/apache/solr/search/join/BlockJoinChildQParser.java
@@ -34,7 +34,7 @@ public class BlockJoinChildQParser extends BlockJoinParentQParser {
 
   @Override
   protected Query createQuery(Query parentListQuery, Query query, String scoreMode) {
-    return new ToChildBlockJoinQuery(query, getFilter(parentListQuery).filter);
+    return new ToChildBlockJoinQuery(query, getFilter(parentListQuery).getFilter());
   }
 
   @Override
diff --git a/solr/core/src/java/org/apache/solr/search/join/BlockJoinParentQParser.java b/solr/core/src/java/org/apache/solr/search/join/BlockJoinParentQParser.java
index b91cd62..4c5587d 100644
--- a/solr/core/src/java/org/apache/solr/search/join/BlockJoinParentQParser.java
+++ b/solr/core/src/java/org/apache/solr/search/join/BlockJoinParentQParser.java
@@ -84,7 +84,7 @@ public class BlockJoinParentQParser extends FiltersQParser {
     return getCachedFilter(req, parentList);
   }
 
-  static BitDocIdSetFilterWrapper getCachedFilter(final SolrQueryRequest request, Query parentList) {
+  public static BitDocIdSetFilterWrapper getCachedFilter(final SolrQueryRequest request, Query parentList) {
     SolrCache parentCache = request.getSearcher().getCache(CACHE_NAME);
     // lazily retrieve from solr cache
     Filter filter = null;
@@ -122,9 +122,9 @@ public class BlockJoinParentQParser extends FiltersQParser {
   }
 
   // We need this wrapper since BitDocIdSetFilter does not extend Filter
-  static class BitDocIdSetFilterWrapper extends Filter {
+  public static class BitDocIdSetFilterWrapper extends Filter {
 
-    final BitSetProducer filter;
+    private final BitSetProducer filter;
 
     BitDocIdSetFilterWrapper(BitSetProducer filter) {
       this.filter = filter;
@@ -139,6 +139,10 @@ public class BlockJoinParentQParser extends FiltersQParser {
       return BitsFilteredDocIdSet.wrap(new BitDocIdSet(set), acceptDocs);
     }
 
+    public BitSetProducer getFilter() {
+      return filter;
+    }
+
     @Override
     public String toString(String field) {
       return getClass().getSimpleName() + "(" + filter + ")";
@@ -147,14 +151,13 @@ public class BlockJoinParentQParser extends FiltersQParser {
     @Override
     public boolean equals(Object other) {
       return sameClassAs(other) &&
-             Objects.equals(filter, getClass().cast(other).filter);
+             Objects.equals(filter, getClass().cast(other).getFilter());
     }
 
     @Override
     public int hashCode() {
       return classHash() + filter.hashCode();
     }
-
   }
 
 }
diff --git a/solr/core/src/java/org/apache/solr/search/join/ChildFieldValueSourceParser.java b/solr/core/src/java/org/apache/solr/search/join/ChildFieldValueSourceParser.java
index aa2b77d..b6312d5 100644
--- a/solr/core/src/java/org/apache/solr/search/join/ChildFieldValueSourceParser.java
+++ b/solr/core/src/java/org/apache/solr/search/join/ChildFieldValueSourceParser.java
@@ -177,8 +177,8 @@ public class ChildFieldValueSourceParser extends ValueSourceParser {
       }
       bjQ = (AllParentsAware) query;
       
-      parentFilter = BlockJoinParentQParser.getCachedFilter(fp.getReq(), bjQ.getParentQuery()).filter;
-      childFilter = BlockJoinParentQParser.getCachedFilter(fp.getReq(), bjQ.getChildQuery()).filter;
+      parentFilter = BlockJoinParentQParser.getCachedFilter(fp.getReq(), bjQ.getParentQuery()).getFilter();
+      childFilter = BlockJoinParentQParser.getCachedFilter(fp.getReq(), bjQ.getChildQuery()).getFilter();
 
       if (sortFieldName==null || sortFieldName.equals("")) {
         throw new SyntaxError ("field is omitted in "+fp.getString());
diff --git a/solr/core/src/test/org/apache/solr/search/join/another/BJQFilterAccessibleTest.java b/solr/core/src/test/org/apache/solr/search/join/another/BJQFilterAccessibleTest.java
new file mode 100644
index 0000000..6764f75
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/search/join/another/BJQFilterAccessibleTest.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.apache.solr.search.join.another;
+
+import java.io.IOException;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.WildcardQuery;
+import org.apache.lucene.search.join.ScoreMode;
+import org.apache.lucene.search.join.ToParentBlockJoinQuery;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.search.join.BlockJoinParentQParser;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+
+import static org.apache.solr.search.join.BJQParserTest.createIndex;
+
+public class BJQFilterAccessibleTest  extends SolrTestCaseJ4 {
+
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    initCore("solrconfig.xml", "schema15.xml");
+    createIndex();
+  }
+
+  public void testAbilityToCreateBJQfromAnotherPackage() throws IOException {
+    try (SolrQueryRequest req = lrf.makeRequest()) {
+      TermQuery childQuery = new TermQuery(new Term("child_s", "l"));
+      Query parentQuery = new WildcardQuery(new Term("parent_s", "*"));
+      ToParentBlockJoinQuery tpbjq = new ToParentBlockJoinQuery(childQuery, BlockJoinParentQParser.getCachedFilter(req,parentQuery).getFilter(), ScoreMode.Max);
+      Assert.assertEquals(6, req.getSearcher().search(tpbjq,10).totalHits.value);
+    }
+  }
+}