@Override protected void addClause(final NodeBooleanQuery topLevel, final Term term, final int docFreq, final float boost, final TermContext states) { final NodeQuery q = new NodeConstantScoreQuery(new NodeTermQuery(term, states)); q.setBoost(boost); topLevel.add(q, NodeBooleanClause.Occur.SHOULD); } }
@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; }
@Override public Query rewrite(final IndexReader reader) throws IOException { final Query rewroteQuery = nodeQuery.rewrite(reader); if (nodeQuery == rewroteQuery) { return this; } final LuceneProxyNodeQuery q = new LuceneProxyNodeQuery((NodeQuery) rewroteQuery); q.setBoost(nodeQuery.getBoost()); return q; }
@Override public void setLevelConstraint(final int levelConstraint) { super.setLevelConstraint(levelConstraint); // keep clauses synchronised for (final NodeBooleanClause clause : clauses) { clause.getQuery().setLevelConstraint(levelConstraint); } }
@Override public int nextDoc() throws IOException { while (scorer.nextCandidateDocument()) { if (scorer.nextNode()) { // check if there is at least 1 node that matches the query return this.docID(); } } return NO_MORE_DOCS; }
@Override public NodeQuery rewrite(final IndexReader reader) throws IOException { if (query != null) { NodeQuery rewritten = (NodeQuery) query.rewrite(reader); if (rewritten != query) { rewritten = new NodeConstantScoreQuery(rewritten); rewritten.setBoost(this.getBoost()); return rewritten; } } return this; }
/** * 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)); }
@Override public void setAncestorPointer(final NodeQuery ancestor) { super.setAncestorPointer(ancestor); // keep clauses synchronised for (final NodeBooleanClause clause : clauses) { clause.getQuery().setAncestorPointer(ancestor); } }
@Override public boolean nextNode() throws IOException { if (!reqScorer.nextNode()) { // Move to the next matching node return false; // exhausted, nothing left } if (exclScorer == null || exclScorer.doc() != reqScorer.doc()) { return true; // reqScorer.nextNode() already returned true } // reqScorer and exclScorer are positioned on the same candidate document return this.toNonExcludedNode(); }
@Override public void setNodeConstraint(final int lowerBound, final int upperBound) { super.setNodeConstraint(lowerBound, upperBound); // keep encapsulated query synchronised query.setNodeConstraint(lowerBound, upperBound); }
/** * 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 boolean nextCandidateDocument() throws IOException { if (!reqScorer.nextCandidateDocument()) { return false; } if (exclScorer == null) { return true; // reqScorer.nextCandidateDocument() already returned true } return this.toNonExcludedCandidateDocument(); }
@Override public boolean skipToCandidate(final int target) throws IOException { if (exclScorer == null) { return reqScorer.skipToCandidate(target); } if (!reqScorer.skipToCandidate(target)) { return false; } return this.toNonExcludedCandidateDocument(); }
@Override public boolean nextNode() throws IOException { freq = 0; // reset freq while (conjunctionScorer.nextNode()) { // if node contains phrase-query terms if (this.firstPhrase()) { // check for phrase // TODO: Instead of computing the full phraseFreq, we could defer it until freqInNode or scoreInNode is called. freq = this.phraseFreq(); // compute frequency of the phrase return true; } } return false; }
@Override boolean firstPhrase() throws IOException { for (final NodePhrasePosition phrasePosition : phrasePositions) { phrasePosition.init(); } // check for phrase return this.nextPhrase(); }
private void retrieveConstraint(final NodeQuery query, final ConstraintStack stack) { if (query == null) { return; } // add a constraint only if lower and upper bounds are defined if (query.lowerBound != -1 && query.upperBound != -1) { stack.add(query.levelConstraint, query.lowerBound, query.upperBound); } // recursively traverse the ancestors this.retrieveConstraint(query.ancestor, stack); }
private NodeScorer countingDisjunctionSumScorer(final List<NodeScorer> scorers) throws IOException { return new NodeDisjunctionScorer(this.getWeight(), scorers) { @Override public float scoreInNode() throws IOException { final float nodeScore = super.scoreInNode(); coordinator.nrMatchers += super.nrMatchers(); return nodeScore; } }; }
@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; }