1 package org.apache.lucene.search; 2 3 18 19 import org.apache.lucene.index.TermPositions; 20 21 import java.io.IOException ; 22 23 final class SloppyPhraseScorer extends PhraseScorer { 24 private int slop; 25 26 SloppyPhraseScorer(Weight weight, TermPositions[] tps, int[] positions, Similarity similarity, 27 int slop, byte[] norms) { 28 super(weight, tps, positions, similarity, norms); 29 this.slop = slop; 30 } 31 32 protected final float phraseFreq() throws IOException { 33 pq.clear(); 34 int end = 0; 35 for (PhrasePositions pp = first; pp != null; pp = pp.next) { 36 pp.firstPosition(); 37 if (pp.position > end) 38 end = pp.position; 39 pq.put(pp); } 41 42 float freq = 0.0f; 43 boolean done = false; 44 do { 45 PhrasePositions pp = (PhrasePositions) pq.pop(); 46 int start = pp.position; 47 int next = ((PhrasePositions) pq.top()).position; 48 for (int pos = start; pos <= next; pos = pp.position) { 49 start = pos; if (!pp.nextPosition()) { 51 done = true; break; 53 } 54 } 55 56 int matchLength = end - start; 57 if (matchLength <= slop) 58 freq += getSimilarity().sloppyFreq(matchLength); 60 if (pp.position > end) 61 end = pp.position; 62 pq.put(pp); } while (!done); 64 65 return freq; 66 } 67 } 68 | Popular Tags |