def test_union(self): s1 = FakeScorer(1, 2, 3, 4, 5, 6, 7, 8) s2 = FakeScorer(2, 4, 8, 10, 20, 30) s3 = FakeScorer(10, 100, 200) result = [1, 2, 3, 4, 5, 6, 7, 8, 10, 20, 30, 100, 200] uqs = UnionScorer([s1, s2, s3]) self.assertEqual(list(uqs.ids()), result)
def test_union_scores(self): s1 = FakeScorer(1, 2, 3) s2 = FakeScorer(2, 4, 8) s3 = FakeScorer(2, 3, 8) result = [(1, 10), (2, 30), (3, 20), (4, 10), (8, 20)] uqs = UnionScorer([s1, s2, s3]) self.assertEqual(list(uqs), result)
def test_random_union(self): testcount = 1000 rangelimits = (2, 10) clauselimits = (2, 10) vals = range(100) for testnum in xrange(testcount): matches = set() scorers = [] for _ in xrange(randint(*clauselimits)): nums = sample(vals, randint(*rangelimits)) matches = matches.union(nums) scorers.append(FakeScorer(*sorted(nums))) matches = sorted(matches) uqs = UnionScorer(scorers) self.assertEqual(list(uqs.ids()), matches)
def scorer(self, searcher, exclude_docs=None): fn = self.fieldname scorers = [] for word in self._words(searcher.reader()): try: q = Term(fn, word).scorer(searcher, exclude_docs=exclude_docs) scorers.append(q) except TermNotFound: pass if scorers: return UnionScorer(scorers, boost=self.boost) else: return EmptyScorer()
def test_union(self): c1, c2, c3 = self.make_readers() idset = sorted(set(c1.ids + c2.ids + c3.ids)) union = UnionScorer([c1, c2, c3]) self.assertEqual(list(union.all_ids()), idset)