@Override public T visit(final BooleanQuery booleanQuery) { for (final BooleanClause clause : booleanQuery.getClauses()) { clause.accept(this); } return null; }
@Override public Node visit(final BooleanQuery booleanQuery) { final BooleanQuery newBQ = new BooleanQuery((BooleanParent) getNewParent(), booleanQuery.occur, true); newParentStack.add(newBQ); for (final BooleanClause clause : booleanQuery.getClauses()) { newBQ.addClause((BooleanClause) clause.accept(this)); } newParentStack.removeLast(); return newBQ; }
public void removeIfNotOnlyChild(final Term term) { // remove the term from its parent. If the parent doesn't have any further child, // remove the parent from the grand-parent. If this also hasn't any further child, // do not remove anything // TODO: go until top level? final DisjunctionMaxQuery parentQuery = term.getParent(); if (parentQuery.getClauses().size() > 1) { parentQuery.removeClause(term); } else { final BooleanQuery grandParent = parentQuery.getParent(); if (grandParent != null && grandParent.getClauses().size() > 1) { grandParent.removeClause(parentQuery); } } }
if (grandParent.getClauses().size() < 2) { continue;
final List<BooleanClause> clauses = query.getClauses();
@Test public void testThatGeneratedIsPropagatedToClauses() throws Exception { BooleanQuery bq = new BooleanQuery(null, SHOULD, false); DisjunctionMaxQuery dmq = new DisjunctionMaxQuery(bq, Clause.Occur.SHOULD, false); bq.addClause(dmq); dmq.addClause(new Term(dmq, "Test", false)); final BooleanQuery clone = (BooleanQuery) bq.clone(null, MUST, true); assertThat(clone, bq(must(), dmq(should(), term("Test", true)))); assertTrue(clone.isGenerated()); assertTrue(clone.getClauses().get(0).isGenerated()); assertEquals(MUST, clone.getOccur()); } }