import os from whoosh.index import create_in, open_dir from whoosh.fields import Schema, TEXT from whoosh.qparser import QueryParser schema = Schema(title=TEXT(stored=True), content=TEXT) if not os.path.exists("index"): os.mkdir("index") index = open_dir("index") if os.path.exists("index") else create_in("index", schema) searcher = index.searcher() parser = QueryParser("content", schema=index.schema) query = parser.parse(query_text) results = searcher.search(query) for result in results: print(result["title"]) searcher.close()


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