Я думаю, вам нужно использовать 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
будет глобальной частотой.