@Override public boolean nextCandidateDocument() throws IOException { // reset currentNode and matchStart this.resetCurrentNode(); this.resetStart(); if (!scorer.nextCandidateDocument()) { return false; } this.pendingNode = false; return true; }
@Override public boolean nextNode() throws IOException { // reset matchStart this.resetStart(); // reset flag for pending position pendingPosition = true; if (pendingNode) { pendingNode = false; return true; } else { return this.toNextParent(); } }
/** * Move to the next parent */ private boolean toNextParent() throws IOException { // update previous so that previous = current at the start of the loop this.updatePreviousNode(); // move to the next node while parents are equal while (NodeUtils.compare(parentCurrentNode, parentPreviousNode) == 0) { if (!scorer.nextNode()) { this.updatePreviousNode(); this.updateCurrentNode(); return false; } this.updatePreviousNode(); this.updateCurrentNode(); } return true; }
private void updatePreviousNode() { // set current to previous ArrayUtils.shallowCopy(currentNode, previousNode); // update the parents this.setParent(previousNode, parentPreviousNode); }
@Override public Scorer scorer(final AtomicReaderContext context, final Bits acceptDocs) throws IOException { Scorer scorer = this.weight.scorer(context, acceptDocs); if (scorer == null) { return null; } if (!(scorer instanceof NodeScorer)) { throw new IllegalArgumentException("NodeScorer expected"); } NodeSpans spans = new NodeSpans((NodeScorer) scorer); return new SpanScorer(this, spans); }
@Override public boolean nextPosition() throws IOException { // the first time we call, we are already positioned on the first child node if (pendingPosition) { pendingPosition = false; matchStart = currentNode.ints[currentNode.offset + currentNode.length - 1]; return true; } // otherwise, move to the next node and check if it belongs to the same parent else { if (!scorer.nextNode()) { // do not update previous and current node, as we do not want to loose the current matching node // there will be updated next time nextNode is called. matchStart = PositionsIterator.NO_MORE_POS; return false; } this.updatePreviousNode(); this.updateCurrentNode(); // if the next parent node is different than the current parent node, then we have exhausted the position if (NodeUtils.compare(parentCurrentNode, parentPreviousNode) != 0) { matchStart = PositionsIterator.NO_MORE_POS; pendingNode = true; return false; } // update the span start matchStart = currentNode.ints[currentNode.offset + currentNode.length - 1]; pendingNode = false; return true; } }
/** * Reset the {@link #currentNode} to {@link DocsAndNodesIterator#NULL_NODE} */ private void resetCurrentNode() { ArrayUtils.shallowCopy(DocsAndNodesIterator.NULL_NODE, currentNode); this.setParent(currentNode, parentCurrentNode); }
@Override public boolean skipToCandidate(final int target) throws IOException { // reset currentNode and matchStart this.resetCurrentNode(); this.resetStart(); if (!scorer.skipToCandidate(target)) { return false; } this.pendingNode = false; return true; }
private void updateCurrentNode() { // update the current node ArrayUtils.shallowCopy(scorer.node(), currentNode); // update the parents this.setParent(currentNode, parentCurrentNode); }