Ejemplo n.º 1
0
 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])
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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])
Ejemplo n.º 6
0
 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])
Ejemplo n.º 7
0
 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])
Ejemplo n.º 8
0
 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))