'Full-text search using selected `term`.'

@classmethod
def search_bm25(cls, term, weights=None, with_score=False, score_alias='score', explicit_ordering=False):

    if (not weights):
        rank = SQL('rank')
    elif isinstance(weights, dict):
        weight_args = []
        for field in cls._meta.declared_fields:
            weight_args.append(weights.get(field, weights.get(field.name, 1.0)))
        rank = fn.bm25(cls.as_entity(), *weight_args)
    else:
        rank = fn.bm25(cls.as_entity(), *weights)
    selection = ()
    order_by = rank
    if with_score:
        selection = (cls, rank.alias(score_alias))
    if (with_score and (not explicit_ordering)):
        order_by = SQL(score_alias)
    return cls.select(*selection).where(cls.match(FTS5Model.clean_query(term))).order_by(order_by)
