/** * Scores and collects all matching documents. * * @param collector * The collector to which all matching documents are passed through. */ @Override public void score(final Collector collector) throws IOException { collector.setScorer(this); while (this.nextDoc() != NO_MORE_DOCS) { collector.collect(this.docID()); } }
/** * Expert: Collects matching documents in a range. Hook for optimization. Note * that {@link #nextDoc()} must be called once before this method is * called for the first time. * * @param collector * The collector to which all matching documents are passed through. * @param max * Do not score documents past this. * @return true if more matching documents may remain. */ @Override public boolean score(final Collector collector, final int max, final int firstDocID) throws IOException { // firstDocID is ignored since nextDocument() sets 'currentDoc' collector.setScorer(this); while (this.docID() < max) { collector.collect(this.docID()); if (this.nextDoc() == NO_MORE_DOCS) { return false; } } return true; }
float lastScore = 0; assertTrue(scorer.nextDoc() != DocsAndNodesIterator.NO_MORE_DOC); lastLastScore = scorer.score(); assertTrue(scorer.nextDoc() != DocsAndNodesIterator.NO_MORE_DOC); lastScore = scorer.score(); assertTrue("doc=" + scorer.docID() + " lastScore=" + lastLastScore + " score=" + lastScore, lastLastScore > lastScore); assertTrue(scorer.nextDoc() != DocsAndNodesIterator.NO_MORE_DOC); lastLastScore = lastScore; lastScore = scorer.score(); lastLastScore = scorer.score(); assertTrue(scorer.nextDoc() != DocsAndNodesIterator.NO_MORE_DOC); lastLastScore = lastScore; lastScore = scorer.score(); assertFalse(scorer.nextDoc() != DocsAndNodesIterator.NO_MORE_DOC);
@Test public void testScore() throws IOException { this.addDocument("\"Renaud renaud\" \"renaud\" . "); final LuceneProxyNodeScorer scorer = new LuceneProxyNodeScorer(this.getScorer(ntq("renaud"))); assertTrue(scorer.nextDoc() != DocsAndNodesIterator.NO_MORE_DOC); assertEquals(0, scorer.docID()); assertEquals(3.0, scorer.freq(), 0.01); final float score = scorer.score(); assertFalse(score + " != " + 0, score == 0); }