Как использовать свист, чтобы получить термин частоты во всех коллекциях? - PullRequest
0 голосов
/ 27 октября 2018
def scorer(self, searcher, fieldname, text, qf=1):
    """Returns an instance of :class:`whoosh.scoring.Scorer` configured
    for the given searcher, fieldname, and term text.
    """

    raise NotImplementedError(self.__class__.__name__)

Я не знаю аргументов в функции счетчика. Откуда они берутся? То же самое для функции в этом предложении. Если я хочу получить термин частоты во всех коллекциях, а не вес в текущем документе. Как я могу это сделать?

def _score(self, weight, length):
    # Override this method with the actual scoring function
    raise NotImplementedError(self.__class__.__name__)

1 Ответ

0 голосов
/ 19 декабря 2018

Я думаю, вам нужно использовать whoosh.reading.TermInfo. глобальную информацию о терминах можно найти здесь. Обновляется при индексации нового документа.

Как вы сказали, хотите получить термин частоты во всех коллекциях, TermInfo().weight() Полагаю, сделаю это Пример кода:

from whoosh.fields import Schema, TEXT
from whoosh.analysis import StemmingAnalyzer
from whoosh.filedb.filestore import FileStorage
from whoosh import scoring

schema = Schema(body=Text(analyzer=StemAnalyzer(), stored=True))

storage = FileStorage("index")
ix = storage.open_index()

def user_weighting_func(searcher, filename, text, matcher):
    return float(searcher.term_info('body', text))

with ix.searcher(weighting=scoring.FunctionWeighting(user_weighting_func)) as searcher:
    qp = QueryParser("body", schema=schema)
    q = qp.parse("hello")
    result = searcher.search(q)
    for hit in results:
        print(hit.score, hit['body'])

В этом коде hit.score будет глобальной частотой.

...