

def normalize(self):
    subqueries = [q for q in self.subqueries if (q is not NullQuery)]
    if (not subqueries):
        return NullQuery
    subqs = []
    seenterms = set()
    for s in subqueries:
        s = s.normalize()
        if (s is NullQuery):
            continue
        if isinstance(s, Term):
            term = (s.fieldname, s.text)
            if (term in seenterms):
                continue
            seenterms.add(term)
        if isinstance(s, self.__class__):
            subqs += s.subqueries
        else:
            subqs.append(s)
    if (not subqs):
        return NullQuery
    if (len(subqs) == 1):
        return subqs[0]
    return self.__class__(subqs, boost=self.boost)

dataset/ETHPy150Open dokipen/whoosh/src/whoosh/query.py CompoundQuery.normalize/original