Beispiel #1
0
def create_matchers():
    id1 = [i for i in range(1000)]
    id2 = [i + 1 for i in range(1000)]
    id3 = [i * 2 + i % 5 for i in range(1000)]
    id4 = [i * i for i in range(1000)]
    id5 = [1001 - i for i in range(1000)]
    id6 = [i * 3 // 2 for i in range(1000)]
    vl1 = [0.1 for i in range(1000)]
    vl2 = [0.2 for i in range(1000)]
    vl3 = [0.3 for i in range(1000)]
    vl4 = [0.4 for i in range(1000)]
    vl5 = [0.5 for i in range(1000)]
    vl6 = [0.6 for i in range(1000)]
    sc1 = scoring.WeightScorer(0.15)
    sc2 = scoring.WeightScorer(0.25)
    sc3 = scoring.WeightScorer(0.35)
    sc4 = scoring.WeightScorer(0.45)
    sc5 = scoring.WeightScorer(0.55)
    sc6 = scoring.WeightScorer(0.65)
    ls1 = matching.ListMatcher(id1, vl1, sc1)
    ls2 = matching.ListMatcher(id2, vl2, sc2)
    ls3 = matching.ListMatcher(id3, vl3, sc3)
    ls4 = matching.ListMatcher(id4, vl4, sc4)
    ls5 = matching.ListMatcher(id5, vl5, sc5)
    ls6 = matching.ListMatcher(id6, vl6, sc6)
    um1 = matching.UnionMatcher(ls1, ls2)
    um2 = matching.UnionMatcher(ls3, ls4)
    um3 = matching.UnionMatcher(ls5, ls6)
    inv = matching.InverseMatcher(um3, 15)
    mm = matching.MultiMatcher([um1, um2, inv], [0, 9, 18])
    return mm
 def matcher(self, searcher, context=None):
     # Usually only called if Not is the root query. Otherwise, queries such
     # as And and Or do special handling of Not subqueries.
     reader = searcher.reader()
     child = self.query.matcher(searcher, searcher.boolean_context())
     return matching.InverseMatcher(child,
                                    reader.doc_count_all(),
                                    missing=reader.is_deleted)
Beispiel #3
0
 def matcher(self, searcher, weighting=None):
     # Usually only called if Not is the root query. Otherwise, queries such
     # as And and Or do special handling of Not subqueries.
     reader = searcher.reader()
     # Don't bother passing the weighting down, we don't use score anyway
     child = self.query.matcher(searcher)
     return matching.InverseMatcher(child, reader.doc_count_all(),
                                    missing=reader.is_deleted)
def test_inverse():
    s = matching.ListMatcher([1, 5, 10, 11, 13])
    inv = matching.InverseMatcher(s, 15)
    ids = []
    while inv.is_active():
        ids.append(inv.id())
        inv.next()
    assert ids == [0, 2, 3, 4, 6, 7, 8, 9, 12, 14]
def test_inverse_skip():
    s = matching.ListMatcher([1, 5, 10, 11, 13])
    inv = matching.InverseMatcher(s, 15)
    inv.skip_to(8)

    ids = []
    while inv.is_active():
        ids.append(inv.id())
        inv.next()
    assert ids == [8, 9, 12, 14]