def __init__(self, td, n, w): self.termDocs = td self.norms = n self.weight = w self.scoreCache = [ similarity.tf(i) * self.weight for i in range(self.SCORE_CACHE_SIZE) ]
def score(self, end): for d, f in self.termDocs.read(): if d >= end: break if f < self.SCORE_CACHE_SIZE: score = self.scoreCache[f] else: # cache miss score = similarity.tf(f) * self.weight # normalize for field score *= similarity.normByte(self.norms[d]) # collect score yield (d, score) else: # close stream self.termDocs.close() # set to sentinel value self.doc = sys.maxint
def __init__(self, td, n, w): self.termDocs = td self.norms = n self.weight = w self.scoreCache = [similarity.tf(i) * self.weight for i in range(self.SCORE_CACHE_SIZE)]