@Override protected NodeBooleanQuery getTopLevelQuery(final NodeQuery query) { NodeBooleanQuery q = new NodeBooleanQuery(); // set level and node constraints q.setLevelConstraint(query.getLevelConstraint()); q.setNodeConstraint(query.getNodeConstraint()[0], query.getNodeConstraint()[1]); // set ancestor q.setAncestorPointer(query.ancestor); return q; }
/** * Adds a clause to a boolean span query. * * @throws com.sindicetech.siren.search.node.NodeBooleanQuery.TooManyClauses * if the new number of clauses exceeds the maximum clause number * @see com.sindicetech.siren.search.node.NodeBooleanQuery#getMaxClauseCount() */ public void add(final SpanQuery query, final NodeBooleanClause.Occur occur) { this.nodeBooleanQuery.add(query, occur); }
/** Returns the list of clauses in this query. */ public List<NodeBooleanClause> clauses() { return this.nodeBooleanQuery.clauses(); }
private NodeBooleanQueryBuilder(final BooleanBag[] clauses) { nbq = new NodeBooleanQuery(); for (final BooleanBag bag : clauses) { for (final NodeBooleanClause clause : bag.toNodeBooleanClauses()) { nbq.add(clause); } } }
@Test public void testSetLevelConstraint() { final NodeTermQuery ntq = new NodeTermQuery(new Term("field", "value")); final NodeBooleanQuery bq = new NodeBooleanQuery(); bq.add(ntq, Occur.MUST); bq.setLevelConstraint(3); assertEquals(3, bq.getLevelConstraint()); // node queries in node boolean clauses must have been updated assertEquals(3, ntq.getLevelConstraint()); final NodeTermQuery ntq2 = new NodeTermQuery(new Term("field", "value")); bq.add(ntq2, Occur.MUST); // new clause must have been updated assertEquals(3, ntq2.getLevelConstraint()); }
@Test public void testSetAncestor() { final NodeTermQuery ntq = new NodeTermQuery(new Term("field", "value")); final NodeBooleanQuery bq1 = new NodeBooleanQuery(); bq1.add(ntq, Occur.MUST); final NodeBooleanQuery bq2 = new NodeBooleanQuery(); bq1.setAncestorPointer(bq2); assertSame(bq2, bq1.ancestor); // node queries in node boolean clauses must have been updated assertSame(bq2, ntq.ancestor); final NodeTermQuery ntq2 = new NodeTermQuery(new Term("field", "value")); bq1.add(ntq2, Occur.MUST); // new clause must have been updated assertSame(bq2, ntq2.ancestor); }
@Test public void testSetNodeConstraint() { final NodeTermQuery ntq = new NodeTermQuery(new Term("field", "value")); final NodeBooleanQuery bq = new NodeBooleanQuery(); bq.add(ntq, Occur.MUST); bq.setNodeConstraint(2,6); assertEquals(2, bq.lowerBound); assertEquals(6, bq.upperBound); // node queries in node boolean clauses must have been updated assertEquals(2, ntq.lowerBound); assertEquals(6, ntq.upperBound); final NodeTermQuery ntq2 = new NodeTermQuery(new Term("field", "value")); bq.add(ntq2, Occur.MUST); // new clause must have been updated assertEquals(2, ntq2.lowerBound); assertEquals(6, ntq2.upperBound); }
/** Constructs an empty boolean span query. */ public BooleanSpanQuery(final int slop, final boolean inOrder) { this.nodeBooleanQuery = new NodeBooleanQuery(); this.slop = slop; this.inOrder = inOrder; }
@Override public Query rewrite(final IndexReader reader) throws IOException { if (terms.isEmpty()) { final NodeBooleanQuery bq = new NodeBooleanQuery(); bq.setBoost(this.getBoost()); return bq; } else if (terms.size() == 1) { final NodeTermQuery tq = new NodeTermQuery(terms.get(0)); tq.setBoost(this.getBoost()); return tq; } else { return super.rewrite(reader); } }
/** This test should not be here, but it tests the fuzzy query rewrite mode (TOP_TERMS_SCORING_BOOLEAN_REWRITE) * with constant score and checks, that only the lower end of terms is put into the range */ public void testTopTermsRewrite() throws Exception { this.addDocuments(new String[]{"</computera>", "</computerb>", "</computerc>", "</computerd>", "</computere>", "</computerf>", "</computerg>", "</computerh>", "</computeri>", "</computerj>", "</computerk>"}); final NodeTermRangeQuery query = NodeTermRangeQuery.newStringRange(DEFAULT_TEST_FIELD, "/computerb", "/computerj", true, true); this.checkBooleanTerms(query, "/computerb", "/computerc", "/computerd", "/computere", "/computerf", "/computerg", "/computerh", "/computeri", "/computerj"); final int savedClauseCount = NodeBooleanQuery.getMaxClauseCount(); try { NodeBooleanQuery.setMaxClauseCount(3); this.checkBooleanTerms(query, "/computerb", "/computerc", "/computerd"); } finally { NodeBooleanQuery.setMaxClauseCount(savedClauseCount); } }
public SirenQParser(final String qstr, final SolrParams localParams, final SolrParams params, final SolrQueryRequest req) { super(qstr, localParams, params, req); // change the BooleanQuery maxClauseCount for ALL cores ... // Since QParserPlugin cannot be SolrCoreAware, we cannot do this at plugin init time int maxClauseCount = req.getCore().getSolrConfig().booleanQueryMaxClauseCount; NodeBooleanQuery.setMaxClauseCount(maxClauseCount); TwigQuery.setMaxClauseCount(maxClauseCount); }
@Override protected int getMaxSize() { return NodeBooleanQuery.getMaxClauseCount(); }
@Override public void setLevelConstraint(final int levelConstraint) { super.setLevelConstraint(levelConstraint); this.nodeBooleanQuery.setLevelConstraint(levelConstraint); }
@Override public void setNodeConstraint(final int lowerBound, final int upperBound) { super.setNodeConstraint(lowerBound, upperBound); this.nodeBooleanQuery.setNodeConstraint(lowerBound, upperBound); }
@Override public void setAncestorPointer(final NodeQuery ancestor) { super.setAncestorPointer(ancestor); this.nodeBooleanQuery.setAncestorPointer(ancestor); }
@Test public void testEquality() throws Exception { final NodeBooleanQuery bq1 = new NodeBooleanQuery(); bq1.add(new NodeTermQuery(new Term("field", "value1")), NodeBooleanClause.Occur.SHOULD); bq1.add(new NodeTermQuery(new Term("field", "value2")), NodeBooleanClause.Occur.SHOULD); final NodeBooleanQuery bq2 = new NodeBooleanQuery(); bq2.add(new NodeTermQuery(new Term("field", "value1")), NodeBooleanClause.Occur.SHOULD); bq2.add(new NodeTermQuery(new Term("field", "value2")), NodeBooleanClause.Occur.SHOULD); assertEquals(bq2, bq1); }
@Override public Query rewrite(IndexReader reader) throws IOException { return new NodeBooleanQuery(); } }
@Override @Before public void setUp() throws Exception { super.setUp(); // Remove maximum clause limit for the tests NodeBooleanQuery.setMaxClauseCount(Integer.MAX_VALUE); }
@Override protected int getMaxSize() { return NodeBooleanQuery.getMaxClauseCount(); }
@Override protected NodeBooleanQuery getTopLevelQuery(final NodeQuery query) { NodeBooleanQuery q = new NodeBooleanQuery(); // set level and node constraints q.setLevelConstraint(query.getLevelConstraint()); q.setNodeConstraint(query.getNodeConstraint()[0], query.getNodeConstraint()[1]); // set ancestor q.setAncestorPointer(query.ancestor); return q; }