@Override public float scoreInNode() throws IOException { if (currentDoc == -1) { // if nextCandidateDocument not called for the first time return 0; } nodeScorerQueue.countAndSumMatchers(); return nodeScorerQueue.scoreInNode(); }
/** * Returns the number of subscorers matching the current node. Initially * invalid, until {@link #nextCandidateDocument()} is called the first time. * @throws IOException */ public int nrMatchers() throws IOException { // update the number of matched scorers nodeScorerQueue.countAndSumMatchers(); return nodeScorerQueue.nrMatchersInNode(); }
/** * Move all the scorers that have document equals to the top document to the * next node and adjust the heap. * * @return If the least scorer has no more nodes, returns false. */ public final boolean nextNodeAndAdjust() throws IOException { /* * TODO: stecam: I had a NPE in this method with topHSN. However, * I cannot reproduce it. Try to find the case it does occur. */ // count number of scorers having the same document and node // counting the number of scorers and then performing the iterations of // all the scorers allows to avoid a node array copy (i.e., current node cache) if (size > 0 && nrMatchersInNode < 0) { this.countAndSumMatchers(); } // Move the scorers to the next node for (int i = 0; i < nrMatchersInNode; i++) { topHSN.scorer.nextNode(); this.adjustTop(); } // reset nrMatchersInNode nrMatchersInNode = -1; // if top node has sentinel value, it means that there is no more nodes return this.node() != DocsAndNodesIterator.NO_MORE_NOD; }
@Test public void testNrMatches() throws IOException { this.addDocument("\"term1\" \"term2\" . \"term3\" . \"term4\" . "); this.addDocument("\"term2\" \"term3\" . \"term5\" . "); this.addDocument("\"term2\" \"term1 term5\" . "); final NodeDisjunctionScorerQueue q = new NodeDisjunctionScorerQueue(2); q.put(this.getScorer(ntq("term1"))); q.put(this.getScorer(ntq("term5"))); assertEquals(0, q.doc()); assertTrue(q.nextNodeAndAdjust()); q.countAndSumMatchers(); // there must be 1 matchers for node {0,0} assertEquals(1, q.nrMatchersInNode()); assertTrue(q.nextCandidateDocumentAndAdjustElsePop()); assertEquals(1, q.doc()); assertTrue(q.nextNodeAndAdjust()); q.countAndSumMatchers(); // there must be 1 matchers for node {1,0} assertEquals(1, q.nrMatchersInNode()); assertTrue(q.nextCandidateDocumentAndAdjustElsePop()); assertEquals(2, q.doc()); assertTrue(q.nextNodeAndAdjust()); q.countAndSumMatchers(); // there must be 2 matchers for node {0,1} assertEquals(2, q.nrMatchersInNode()); }
@Test public void testScoreSum() throws IOException { this.addDocument("\"term1 term2 term3\" . \"term4\" . "); final NodeScorer s1 = this.getScorer(ntq("term1")); final NodeScorer s2 = this.getScorer(ntq("term2")); final NodeScorer s3 = this.getScorer(ntq("term3")); final NodeDisjunctionScorerQueue q = new NodeDisjunctionScorerQueue(3); q.put(s1); q.put(s2); q.put(s3); assertEquals(0, q.doc()); assertTrue(q.nextNodeAndAdjust()); q.countAndSumMatchers(); // there must be 3 matchers assertEquals(3, q.nrMatchersInNode()); final float scoreInNode = q.scoreInNode(); assertEquals(s1.scoreInNode() + s2.scoreInNode() + s3.scoreInNode(), scoreInNode, 0f); assertTrue(scoreInNode != 0); }