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