@Override public boolean nextCandidateDocument() throws IOException { return reqScorer.nextCandidateDocument(); }
@Override public boolean nextCandidateDocument() throws IOException { return countingSumScorer.nextCandidateDocument(); }
@Override public boolean nextCandidateDocument() throws IOException { return scorer.nextCandidateDocument(); }
@Override public boolean nextCandidateDocument() throws IOException { return scorer.nextCandidateDocument(); }
@Override public boolean nextCandidateDocument() throws IOException { return scorer.nextCandidateDocument(); }
@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 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; }
/** * Adds a SirenPrimitiveScorer to a NodeDisjunctionScorerQueue in log(size) * time. If one tries to add more Scorers than maxSize a RuntimeException * (ArrayIndexOutOfBound) is thrown. * <p> * The scorer is advanced to the next document to initiate heap ordering. */ public final void put(final NodeScorer scorer) throws IOException { if (scorer.nextCandidateDocument()) { // if scorer exhausted, no need to add it size++; heap[size] = new HeapedScorerNode(scorer); this.upHeap(); } }
@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; }
@Override public boolean nextCandidateDocument() throws IOException { if (lastDocument == DocsAndNodesIterator.NO_MORE_DOC) { return false; } else if (lastDocument == -1) { // first time called lastDocument = scorers[scorers.length - 1].doc(); lastNode = scorers[scorers.length - 1].node(); return true; } // advance the last scorer to the next candidate document scorers[(scorers.length - 1)].nextCandidateDocument(); final boolean more = this.doNext(); lastDocument = scorers[scorers.length - 1].doc(); lastNode = scorers[scorers.length - 1].node(); return more; }
/** * 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(expected=UnsupportedOperationException.class) public void testEmptyRootScorer() throws Exception { this.addDocuments( doc(token("aaa", node(1)), token("req", node(1)), token("bbb", node(1,0)), token("ccc", node(1,0))) ); NodeScorer scorer = this.getScorer( twq(1) ); scorer.nextCandidateDocument(); }
@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 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); }