@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 scorer.nextNode(); }
@Override public boolean nextNode() throws IOException { return reqScorer.nextNode(); }
@Override public boolean nextNode() throws IOException { return countingSumScorer.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()); } }
@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 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 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 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); }
@Test public void testTupleConstraintOneClause() throws IOException { this.addDocument("<aaa> <bbb> . <ccc> <ddd> . "); this.addDocument("<ccc> . <aaa> <bbb> <ddd> . "); final NodeScorer scorer = this.getScorer( tuple().with(nbq(must("ccc"))) .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); }
/** * <code>{[ddd] [eee]}</code> */ @Test public void testShould() throws IOException { this.addDocument("\"eee\" \"ddd\" . "); this.addDocument("\"bbb\" \"ddd\" . "); final NodeScorer scorer = this.getScorer( tuple().optional(nbq(should("ddd"))) .optional(nbq(should("eee"))) ); // the two documents match assertTrue(scorer.nextCandidateDocument()); assertEquals(0, scorer.doc()); assertTrue(scorer.nextNode()); assertEquals(node(0), scorer.node()); assertTrue(scorer.nextCandidateDocument()); assertEquals(1, scorer.doc()); assertTrue(scorer.nextNode()); assertEquals(node(0), 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); }
@Test public void testMultiValuedPredicate2() throws CorruptIndexException, IOException { final String[] docs = new String[300]; for (int i = 0; i < 100; i++) { docs[i * 3] = "<http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#publicationTag> \"data data figure obtained\" \"belief tln parameters graphical\" \"incorrect rose proportions feature\" ."; docs[i * 3 + 1] = "<http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#publicationTag> \"statistical determining data ylx\" \"presented assumed mit factors\" \"jolla developed positive functions\" ."; docs[i * 3 + 2] = "<http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#publicationTag> \"data accuracy minutes applying\" \"focus perceive em parameterization\" \"yield learning separation rule\" ."; } this.addDocuments(docs); final NodeScorer scorer = this.getScorer( tuple().with(nbq(must("http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#publicationtag")).bound(0,0)) .with(nbq(must("data"), must("accuracy")).bound(1,Integer.MAX_VALUE)) ); for (int i = 0; i < 100; i++) { // first and second documents should be skipped // third candidate document matches assertTrue(scorer.nextCandidateDocument()); assertTrue(scorer.nextNode()); assertEquals(node(0), scorer.node()); } assertEndOfStream(scorer); }