@Override public boolean nextNode() throws IOException { return scorer.nextNode(); }
@Override public boolean nextNode() throws IOException { return scorer.nextNode(); }
@Override public boolean nextNode() throws IOException { return reqScorer.nextNode(); }
@Override public boolean nextNode() throws IOException { return countingSumScorer.nextNode(); }
@Override public boolean nextNode() throws IOException { return scorer.nextNode(); }
@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 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 int advance(final int target) throws IOException { if (scorer.skipToCandidate(target)) { do { if (scorer.nextNode()) { return this.docID(); } } while (scorer.nextCandidateDocument()); } return NO_MORE_DOCS; }
/** * Compute the score and the frequency of the current document * @throws IOException */ private void computeScoreAndFreq() throws IOException { final int doc = this.docID(); if (doc != lastDoc) { lastDoc = doc; score = 0; freq = 0; do { // nextNode() was already called in nextDoc() or in advance() score += scorer.scoreInNode(); freq += scorer.freqInNode(); } while (scorer.nextNode()); } }
@Override public Explanation explain(final AtomicReaderContext context, final int doc) throws IOException { final NodeScorer scorer = (NodeScorer) this.scorer(context, context.reader().getLiveDocs()); if (scorer != null) { if (scorer.skipToCandidate(doc) && scorer.doc() == doc && scorer.nextNode()) { return includeWeight.explain(context, doc); } } return new ComplexExplanation(false, 0.0f, "no matching term"); }
/** * 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; }
@Test public void testNextNodeFail() throws Exception { this.addDocument("<http://renaud.delbru.fr/> . "); final NodeScorer scorer = this.getScorer(ntq("renaud")); assertFalse(scorer.nextNode()); }
/** * Assert if a scorer reaches end of stream, and check if sentinel values are * set. */ public static void assertEndOfStream(final NodeScorer scorer) throws IOException { assertFalse(scorer.nextCandidateDocument()); assertEquals(DocsAndNodesIterator.NO_MORE_DOC, scorer.doc()); assertFalse(scorer.nextNode()); assertEquals(DocsAndNodesIterator.NO_MORE_NOD, scorer.node()); }
@Test public void testLevelConstraint() throws Exception { this.addDocument("<http://renaud.delbru.fr/> . "); NodeScorer scorer = this.getScorer(ntq("renaud").level(1)); assertTrue(scorer.nextCandidateDocument()); assertEquals(0, scorer.doc()); assertFalse(scorer.nextNode()); scorer = this.getScorer(ntq("renaud").level(3)); assertTrue(scorer.nextCandidateDocument()); assertEquals(0, scorer.doc()); assertFalse(scorer.nextNode()); scorer = this.getScorer(ntq("renaud").level(2)); assertTrue(scorer.nextCandidateDocument()); assertEquals(0, scorer.doc()); assertTrue(scorer.nextNode()); assertEquals(node(0,0), scorer.node()); }
@Test public void testIntervalConstraint() throws Exception { this.addDocument("<http://renaud.delbru.fr/> . "); NodeScorer scorer = this.getScorer(ntq("renaud").bound(1,1)); assertTrue(scorer.nextCandidateDocument()); assertEquals(0, scorer.doc()); assertFalse(scorer.nextNode()); scorer = this.getScorer(ntq("renaud").bound(1,2)); assertTrue(scorer.nextCandidateDocument()); assertEquals(0, scorer.doc()); assertFalse(scorer.nextNode()); scorer = this.getScorer(ntq("renaud").bound(0,0)); assertTrue(scorer.nextCandidateDocument()); assertEquals(0, scorer.doc()); assertTrue(scorer.nextNode()); assertEquals(node(0,0), scorer.node()); }
@Test public void testNoNode() throws IOException { this.addDocument("\"eee\" . \"ddd\" . "); final NodeScorer scorer = this.getScorer( nbq(must("ddd"), must("eee")) ); assertTrue(scorer.nextCandidateDocument()); assertFalse(scorer.nextNode()); assertEquals(DocsAndNodesIterator.NO_MORE_NOD, scorer.node()); assertEndOfStream(scorer); }
@Test public void testNextWithPhraseExclusion2() throws Exception { this.addDocument("\"aaa bbb ccc\" . \"ccc aaa bbb\" . "); final NodeScorer scorer = this.getScorer( nbq(must(npq("aaa", "bbb")), not(npq("bbb", "ccc"))) ); assertTrue(scorer.nextCandidateDocument()); assertEquals(0, scorer.doc()); assertEquals(node(-1), scorer.node()); assertTrue(scorer.nextNode()); assertEquals(node(1,0), scorer.node()); assertFalse(scorer.nextNode()); assertEquals(DocsAndNodesIterator.NO_MORE_NOD, scorer.node()); assertEndOfStream(scorer); }
/** * <code>{+[ddd] +[eee]}</code> */ @Test public void testMust() throws IOException { this.addDocument("\"eee\" . \"ddd\" . "); this.addDocument("\"bbb\" . \"ddd eee\" . "); final NodeScorer scorer = this.getScorer( tuple().with(nbq(should("ddd"))) .with(nbq(should("eee"))) ); // first candidate document does not match assertTrue(scorer.nextCandidateDocument()); assertEquals(0, scorer.doc()); assertFalse(scorer.nextNode()); // second candidate document is matching assertTrue(scorer.nextCandidateDocument()); assertEquals(1, scorer.doc()); assertTrue(scorer.nextNode()); assertEquals(node(1), scorer.node()); assertEndOfStream(scorer); }
@Test public void testTupleConstraintTwoClauses() throws IOException { this.addDocument("<aaa> <bbb> . <ccc> <ddd> . "); this.addDocument("<ccc> <ddd> . <aaa> <bbb> <ddd> . "); final NodeScorer scorer = this.getScorer( tuple().with(nbq(must("ccc")).bound(0,0)) .with(nbq(must("ddd")).bound(1,1)) .bound(1, 1) ); // first document matches assertTrue(scorer.nextCandidateDocument()); assertEquals(0, scorer.doc()); assertTrue(scorer.nextNode()); assertEquals(node(1), scorer.node()); // second candidate document do not match assertTrue(scorer.nextCandidateDocument()); assertEquals(1, scorer.doc()); assertFalse(scorer.nextNode()); assertEndOfStream(scorer); }
@Test public void testMoreThanOneClause() throws IOException { this.addDocument("\"aaa ccc\" \"bbb ccc\" . \"aaa bbb\" \"ccc eee\" . "); NodeScorer scorer = this.getScorer( tuple().with(nbq(must("aaa"), must("ccc"))) .with(nbq(must("aaa"), must("bbb"))) ); assertTrue(scorer.nextCandidateDocument()); assertEquals(0, scorer.doc()); assertFalse(scorer.nextNode()); assertEndOfStream(scorer); scorer = this.getScorer( tuple().with(nbq(must("aaa"), must("ccc"))) .with(nbq(must("bbb"), must("ccc"))) ); assertTrue(scorer.nextCandidateDocument()); assertEquals(0, scorer.doc()); assertTrue(scorer.nextNode()); assertEquals(node(0), scorer.node()); assertEndOfStream(scorer); }