SOLR-13720: BlockJoinParentQParser.getCachedFilter made public

This commit is contained in:
Mikhail Khludnev 2019-08-29 17:36:48 +03:00
parent 12715da544
commit c857c1da3d
5 changed files with 66 additions and 8 deletions

View File

@ -89,6 +89,9 @@ Improvements
* SOLR-13542: Code cleanup - Avoid using stream filter count where possible (Koen De Groote via Tomás Fernández Löbbe) * 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 Bug Fixes
---------------------- ----------------------

View File

@ -34,7 +34,7 @@ public class BlockJoinChildQParser extends BlockJoinParentQParser {
@Override @Override
protected Query createQuery(Query parentListQuery, Query query, String scoreMode) { protected Query createQuery(Query parentListQuery, Query query, String scoreMode) {
return new ToChildBlockJoinQuery(query, getFilter(parentListQuery).filter); return new ToChildBlockJoinQuery(query, getFilter(parentListQuery).getFilter());
} }
@Override @Override

View File

@ -84,7 +84,7 @@ public class BlockJoinParentQParser extends FiltersQParser {
return getCachedFilter(req, parentList); 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); SolrCache parentCache = request.getSearcher().getCache(CACHE_NAME);
// lazily retrieve from solr cache // lazily retrieve from solr cache
Filter filter = null; Filter filter = null;
@ -122,9 +122,9 @@ public class BlockJoinParentQParser extends FiltersQParser {
} }
// We need this wrapper since BitDocIdSetFilter does not extend Filter // 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) { BitDocIdSetFilterWrapper(BitSetProducer filter) {
this.filter = filter; this.filter = filter;
@ -139,6 +139,10 @@ public class BlockJoinParentQParser extends FiltersQParser {
return BitsFilteredDocIdSet.wrap(new BitDocIdSet(set), acceptDocs); return BitsFilteredDocIdSet.wrap(new BitDocIdSet(set), acceptDocs);
} }
public BitSetProducer getFilter() {
return filter;
}
@Override @Override
public String toString(String field) { public String toString(String field) {
return getClass().getSimpleName() + "(" + filter + ")"; return getClass().getSimpleName() + "(" + filter + ")";
@ -147,14 +151,13 @@ public class BlockJoinParentQParser extends FiltersQParser {
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
return sameClassAs(other) && return sameClassAs(other) &&
Objects.equals(filter, getClass().cast(other).filter); Objects.equals(filter, getClass().cast(other).getFilter());
} }
@Override @Override
public int hashCode() { public int hashCode() {
return classHash() + filter.hashCode(); return classHash() + filter.hashCode();
} }
} }
} }

View File

@ -177,8 +177,8 @@ public class ChildFieldValueSourceParser extends ValueSourceParser {
} }
bjQ = (AllParentsAware) query; bjQ = (AllParentsAware) query;
parentFilter = BlockJoinParentQParser.getCachedFilter(fp.getReq(), bjQ.getParentQuery()).filter; parentFilter = BlockJoinParentQParser.getCachedFilter(fp.getReq(), bjQ.getParentQuery()).getFilter();
childFilter = BlockJoinParentQParser.getCachedFilter(fp.getReq(), bjQ.getChildQuery()).filter; childFilter = BlockJoinParentQParser.getCachedFilter(fp.getReq(), bjQ.getChildQuery()).getFilter();
if (sortFieldName==null || sortFieldName.equals("")) { if (sortFieldName==null || sortFieldName.equals("")) {
throw new SyntaxError ("field is omitted in "+fp.getString()); throw new SyntaxError ("field is omitted in "+fp.getString());

View File

@ -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);
}
}
}