@Override public void setLevelConstraint(final int levelConstraint) { super.setLevelConstraint(levelConstraint); // keep clauses synchronised for (final NodeBooleanClause clause : clauses) { clause.getQuery().setLevelConstraint(levelConstraint); } }
/** * Constructs an empty twig query at a given level */ public TwigQuery(final int rootLevel) { // set an empty root this.root = new EmptyRootQuery(); // set level constraint super.setLevelConstraint(rootLevel); root.setLevelConstraint(rootLevel); }
@Override public void setLevelConstraint(final int levelConstraint) { super.setLevelConstraint(levelConstraint); // keep encapsulated query synchronised query.setLevelConstraint(levelConstraint); }
@Override public void setLevelConstraint(final int levelConstraint) { super.setLevelConstraint(levelConstraint); this.query.setLevelConstraint(levelConstraint); }
@Override public void setLevelConstraint(final int levelConstraint) { // Do not update the level constraint if it is the sentinel value - cf. #19 if (levelConstraint != -1) { // store the current level constraint before updating final int oldLevelConstraint = this.levelConstraint; // update level constraint super.setLevelConstraint(levelConstraint); // update level constraint of the root root.setLevelConstraint(levelConstraint); // update level of childs and descendants NodeQuery q; for (final NodeBooleanClause clause : clauses) { q = clause.getQuery(); // compute delta between old level and descendant level final int levelDelta = q.getLevelConstraint() - oldLevelConstraint; // update level of descendant q.setLevelConstraint(levelConstraint + levelDelta); } } }
@Override protected void initWeights(final IndexSearcher searcher) throws IOException { weights = new ArrayList<Weight>(clauses.size()); for (int i = 0; i < clauses.size(); i++) { final NodeBooleanClause c = clauses.get(i); final NodeQuery q = c.getQuery(); // pass to child query the node constraints q.setNodeConstraint(lowerBound, upperBound); q.setLevelConstraint(levelConstraint); // transfer ancestor pointer to child q.setAncestorPointer(ancestor); weights.add(q.createWeight(searcher)); } }
/** * Adds a root query. * <p> * Overwrite the level and node constraints of the root query with the * currently defined level and node constraints of the twig query. */ public void addRoot(final NodeQuery root) { this.root = root; // set the node constraint= root.setNodeConstraint(lowerBound, upperBound); // set level constraint root.setLevelConstraint(levelConstraint); // set the ancestor root.setAncestorPointer(ancestor); }
public NodeQueryBuilder level(final int level) { ((NodeQuery) this.getQuery()).setLevelConstraint(level); return this; }
/** * 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)); }
/** * 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 NodeBooleanClause clause) { if (clauses.size() >= maxClauseCount) { throw new TooManyClauses(); } clauses.add(clause); // keep the clause synchronised in term of constraint management clause.getQuery().setLevelConstraint(levelConstraint); clause.getQuery().setNodeConstraint(lowerBound, upperBound); clause.getQuery().setAncestorPointer(ancestor); }
@Override public Query rewrite(final IndexReader reader) throws IOException { NodeSpanQuery clone = null; NodeQuery rewritten = (NodeQuery) this.query.rewrite(reader); if (rewritten != this.query) { clone = this.clone(); // transfer constraints rewritten.setNodeConstraint(lowerBound, upperBound); rewritten.setLevelConstraint(levelConstraint); // transfer ancestor pointer rewritten.setAncestorPointer(ancestor); clone.query = rewritten; } if (clone != null) { return clone; // some clauses rewrote } else { return this; // no clauses rewrote } }
@Override public NodeQuery build(final QueryNode queryNode) throws QueryNodeException { final NodeQueryNode node = (NodeQueryNode) queryNode; final String field = node.getField().toString(); final String expr = node.getValue().toString(); final NodeQuery query = (NodeQuery) keywordParser.parse(expr, field); // check if the node has a level constraint if (node.getTag(LevelPropertyParser.LEVEL_PROPERTY) != null) { query.setLevelConstraint((Integer) node.getTag(LevelPropertyParser.LEVEL_PROPERTY)); } // check if the node has a node range constraint if (node.getTag(RangePropertyParser.RANGE_PROPERTY) != null) { final int[] range = (int[]) node.getTag(RangePropertyParser.RANGE_PROPERTY); query.setNodeConstraint(range[0], range[1]); } return query; }
@Override public NodeQuery build(final QueryNode queryNode) throws QueryNodeException { final NodeQueryNode node = (NodeQueryNode) queryNode; final String field = node.getField().toString(); final String expr = node.getValue().toString(); // ensure that the attribute is unset keywordParser.unsetAttribute(); // set attribute if (node.getAttribute() != null) { keywordParser.setAttribute(node.getAttribute().toString()); } final NodeQuery query = (NodeQuery) keywordParser.parse(expr, field); // check if the node has a level constraint if (node.getTag(LevelPropertyParser.LEVEL_PROPERTY) != null) { query.setLevelConstraint((Integer) node.getTag(LevelPropertyParser.LEVEL_PROPERTY)); } // check if the node has a node range constraint if (node.getTag(RangePropertyParser.RANGE_PROPERTY) != null) { final int[] range = (int[]) node.getTag(RangePropertyParser.RANGE_PROPERTY); query.setNodeConstraint(range[0], range[1]); } return query; }
query.setLevelConstraint(levelConstraint); query.setLevelConstraint(levelConstraint);
@Override public Query toQuery(final boolean proxy) throws QueryNodeException { final com.sindicetech.siren.search.node.NodeQuery query = (com.sindicetech.siren.search.node.NodeQuery) parser.parse(booleanExpression, ""); if (this.hasLevel()) { query.setLevelConstraint(this.getLevel()); } if (this.hasRange()) { query.setNodeConstraint(this.getLowerBound(), this.getUpperBound()); } if (this.hasBoost()) { query.setBoost(this.getBoost()); } // should we wrap the query into a lucene proxy if (proxy) { return new LuceneProxyNodeQuery(query); } return query; }
@Override public Query toQuery(final boolean proxy) throws QueryNodeException { // ensure that the attribute is unset ((ConciseKeywordQueryParser) parser).unsetAttribute(); // set attribute if (this.hasAttribute) { ((ConciseKeywordQueryParser) parser).setAttribute(attribute); } final com.sindicetech.siren.search.node.NodeQuery query = (com.sindicetech.siren.search.node.NodeQuery) parser.parse(booleanExpression, ""); if (this.hasLevel()) { query.setLevelConstraint(this.getLevel()); } if (this.hasRange()) { query.setNodeConstraint(this.getLowerBound(), this.getUpperBound()); } if (this.hasBoost()) { query.setBoost(this.getBoost()); } // should we wrap the query into a lucene proxy if (proxy) { return new LuceneProxyNodeQuery(query); } return query; }