pip install whoosh python from whoosh.index import create_in from whoosh.fields import Schema, TEXT schema = Schema(title=TEXT(stored=True), content=TEXT) ix = create_in("index_dir", schema) writer = ix.writer() writer.commit() python from whoosh.qparser import QueryParser from whoosh import scoring from whoosh.index import open_dir ix = open_dir("index_dir") searcher = ix.searcher(weighting=scoring.TF_IDF()) query_parser = QueryParser("content", schema=ix.schema) results = searcher.search(query) for result in results: print(result['title'], result.score) searcher.close()


上一篇:
下一篇:
切换中文