@Override public Scorer scorer(final AtomicReaderContext context, final Bits acceptDocs) throws IOException { final NodeScorer nodeScorer = (NodeScorer) weight.scorer(context, acceptDocs); return nodeScorer == null ? null // no match : new LuceneProxyNodeScorer(nodeScorer); }
/** * Returns number of matches for the current document. * <p> * Only valid after calling {@link #nextDoc()} or {@link #advance(int)} */ @Override public int freq() throws IOException { this.computeScoreAndFreq(); return freq; }
@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); }
@Override public Explanation explain(final AtomicReaderContext context, final int doc) throws IOException { final LuceneProxyNodeScorer dScorer = (LuceneProxyNodeScorer) this.scorer(context, context.reader().getLiveDocs()); if (dScorer != null) { if (dScorer.advance(doc) != DocIdSetIterator.NO_MORE_DOCS && dScorer.docID() == doc) { final Explanation exp = dScorer.getWeight().explain(context, doc); exp.setValue(dScorer.score()); return exp; } } return new ComplexExplanation(false, 0.0f, "no matching term"); }
@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; }
this.addDocuments(docs); final LuceneProxyNodeScorer scorer = new LuceneProxyNodeScorer(this.getScorer(nbq(must("renaud"), must("delbru")))); 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(); assertTrue("lastScore=" + lastLastScore + " score=" + lastScore, lastLastScore > lastScore); lastLastScore = scorer.score(); assertTrue(scorer.nextDoc() != DocsAndNodesIterator.NO_MORE_DOC); lastLastScore = lastScore; lastScore = scorer.score(); assertFalse(scorer.nextDoc() != DocsAndNodesIterator.NO_MORE_DOC);
@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 float score() throws IOException { this.computeScoreAndFreq(); return score; }