/** * Adds a clause to a boolean query. * * @throws TooManyClauses * if the new number of clauses exceeds the maximum clause number * @see #getMaxClauseCount() */ public void add(final NodeQuery query, final NodeBooleanClause.Occur occur) { this.add(new NodeBooleanClause(query, occur)); }
/** * Adds a descendant clause to the twig query. The node level of the * descendant is relative to the twig level. * * @throws TooManyClauses * if the new number of clauses exceeds the maximum clause number * @see #getMaxClauseCount() */ public void addDescendant(final int nodeLevel, final NodeQuery query, final NodeBooleanClause.Occur occur) { if (nodeLevel <= 0) { throw new IllegalArgumentException("The node level of a descendant should be superior to 0"); } // set the level constraint on the query query.setLevelConstraint(levelConstraint + nodeLevel); // set the ancestor pointer query.setAncestorPointer(root); // add the query to the clauses this.addClause(new NodeBooleanClause(query, occur)); }
/** * Adds a child clause to the twig query. * * @throws TooManyClauses * if the new number of clauses exceeds the maximum clause number * @see #getMaxClauseCount() */ public void addChild(final NodeQuery query, final NodeBooleanClause.Occur occur) { // set the level constraint on the query query.setLevelConstraint(levelConstraint + 1); // set the ancestor pointer query.setAncestorPointer(root); // add the query to the clauses this.addClause(new NodeBooleanClause(query, occur)); }
public NodeBooleanClause[] toNodeBooleanClauses() { final NodeBooleanClause[] clauses = new NodeBooleanClause[queries.size()]; for (int i = 0; i < clauses.length; i++) { final Query q = queries.get(i); if (q instanceof NodeQuery) { final NodeBooleanClause.Occur occur; if (isMust) { occur = NodeBooleanClause.Occur.MUST; } else if (isNot) { occur = NodeBooleanClause.Occur.MUST_NOT; } else if (isShould) { occur = NodeBooleanClause.Occur.SHOULD; } else { // Shouldn't happen throw new IllegalArgumentException("No occurrence could be built!"); } clauses[i] = new NodeBooleanClause((NodeQuery) q, occur); } else { throw new IllegalArgumentException("Building NodeBooleanClauses, " + "expecting only NodeQuery, but got: " + q.getClass().getName()); } } return clauses; }
private TwigQuery rewriteClauses(TwigQuery clone, final IndexReader reader) throws IOException { for (int i = 0 ; i < clauses.size(); i++) { final NodeBooleanClause c = clauses.get(i); final NodeQuery query = (NodeQuery) c.getQuery().rewrite(reader); if (query != c.getQuery()) { // clause rewrote: must clone if (clone == null) { clone = (TwigQuery) this.clone(); // clone and set root since clone is null, i.e., root has not been rewritten clone.root = (NodeQuery) this.root.clone(); // copy ancestor clone.root.setAncestorPointer(ancestor); } // set root as ancestor query.setAncestorPointer(clone.root); clone.clauses.set(i, new NodeBooleanClause(query, c.getOccur())); } } return clone; }
clone.clauses.set(i, new NodeBooleanClause(query, c.getOccur()));