def test_empty_andnot(self): pos = EmptyScorer() neg = EmptyScorer() ans = AndNotScorer(pos, neg) ids = list(ans.all_ids()) self.assertEqual(ids, []) pos = FakeScorer(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) neg = EmptyScorer() ans = AndNotScorer(pos, neg) ids = list(ans.all_ids()) self.assertEqual(ids, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
def test_random_andnot(self): testcount = 100 rangesize = 100 rng = range(rangesize) for testnum in xrange(testcount): negs = sorted(sample(rng, randint(0, rangesize - 1))) negset = frozenset(negs) matched = [n for n in rng if n not in negset] pos = FakeScorer(*rng) neg = FakeScorer(*negs) ans = AndNotScorer(pos, neg) ids = list(ans.all_ids()) self.assertEqual(ids, matched)
def test_random_andnot(self): testcount = 100 rangesize = 100 rng = range(rangesize) for testnum in xrange(testcount): negs = sorted(sample(rng, randint(0, rangesize-1))) negset = frozenset(negs) matched = [n for n in rng if n not in negset] pos = FakeScorer(*rng) neg = FakeScorer(*negs) ans = AndNotScorer(pos, neg) ids = list(ans.all_ids()) self.assertEqual(ids, matched)
def scorer(self, searcher, exclude_docs=None): self._split_queries() exclude_docs = _not_vector(searcher, self._notqueries, exclude_docs) myscorer = self.SCORER([ subquery.scorer(searcher, exclude_docs=exclude_docs) for subquery in self._subqueries ], boost=self.boost) if self._notqueries: notscorer = Or(self._notqueries).normalize().scorer(searcher) return AndNotScorer(myscorer, notscorer) else: return myscorer
def test_andnot(self): pos = FakeScorer(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) neg = FakeScorer(1, 2, 5, 7, 8, 10) ans = AndNotScorer(pos, neg) ids = list(ans.all_ids()) self.assertEqual(ids, [3, 4, 6, 9])
def scorer(self, searcher, exclude_docs=None): return AndNotScorer( self.positive.scorer(searcher, exclude_docs=exclude_docs), self.negative.scorer(searcher, exclude_docs=exclude_docs))