Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.io.UncheckedIOException;
import java.util.Objects;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.ConstantScoreScorer;
import org.apache.lucene.search.ConstantScoreWeight;
import org.apache.lucene.search.DocIdSetIterator;
Expand All @@ -38,10 +40,14 @@
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.ExtendedQueryBase;
import org.apache.solr.search.QParser;


import org.apache.solr.search.SolrCache;
import org.apache.solr.search.SyntaxError;
import org.apache.solr.util.SolrDefaultScorerSupplier;

import static org.apache.solr.search.QueryUtils.makeQueryable;

public class BlockJoinParentQParser extends FiltersQParser {
/** implementation detail subject to change */
public static final String CACHE_NAME = "perSegFilter";
Expand All @@ -68,10 +74,22 @@ protected Query parseParentFilter() throws SyntaxError {
}

@Override
protected Query wrapSubordinateClause(Query subordinate) throws SyntaxError {
protected Query wrapSubordinateClause(Query childrenQuery) throws SyntaxError {
String scoreMode = localParams.get("score", ScoreMode.None.name());
Query parentQ = parseParentFilter();
return createQuery(parentQ, subordinate, scoreMode);

if (childrenQuery instanceof BooleanQuery bq) {

if (bq.clauses().size() == 1) {
BooleanClause bqToFix = bq.clauses().get(0);
Query fixChildQuery = makeQueryable(bqToFix.query());
BooleanQuery.Builder filterFixedChildrenQuery = new BooleanQuery.Builder();
filterFixedChildrenQuery.add(fixChildQuery, BooleanClause.Occur.FILTER);
return createQuery(parentQ, filterFixedChildrenQuery.build(), scoreMode);
}
}

return createQuery(parentQ, childrenQuery, scoreMode);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import org.junit.Test;
import org.junit.rules.TestRule;

public class BJQParserTest extends SolrTestCaseJ4 {
public class BlockJoinQueryParserTest extends SolrTestCaseJ4 {

private static final String[] klm = new String[] {"k", "l", "m"};
private static final List<String> xyz = Arrays.asList("x", "y", "z");
Expand Down Expand Up @@ -163,7 +163,7 @@ public void testFull() {
"//doc/arr[@name=\"parent_s\"]/str='c'",
"//doc/arr[@name=\"parent_s\"]/str='d'",
"//doc/arr[@name=\"parent_s\"]/str='e'",
"//doc/arr[@name=\"parent_s\"]/str='f'"
"//doc/arr[@name=\"parent_s\"]/str='f'",
};

@Test
Expand Down Expand Up @@ -639,6 +639,18 @@ public void testFiltersCache() throws SyntaxError, IOException {
}
}

@Test
public void testPureNegativeQueryInChildFilters() {
assertQ(
req(
"q", "{!parent tag=top filters=$childFq which=$pq}",
"pq", "parent_s:[* TO *]",
"childFq", "-child_s:l -child_s:k"
),
"//*[@numFound='6']"
);
}

@After
public void cleanAfterTestFiltersCache() {
assertU("should be noop", delI("12275"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.solr.search.join.another;

import static org.apache.solr.search.join.BJQParserTest.createIndex;
import static org.apache.solr.search.join.BlockJoinQueryParserTest.createIndex;

import java.io.IOException;
import org.apache.lucene.index.Term;
Expand All @@ -34,7 +34,7 @@
import org.junit.ClassRule;
import org.junit.rules.TestRule;

public class BJQFilterAccessibleTest extends SolrTestCaseJ4 {
public class BlockJoinQueryFilterAccessibleTest extends SolrTestCaseJ4 {

@ClassRule
public static final TestRule noReverseMerge = RandomNoReverseMergePolicyFactory.createRule();
Expand Down