shell pip install Whoosh python from whoosh.index import create_in from whoosh.fields import Schema, TEXT from whoosh.qparser import QueryParser schema = Schema(title=TEXT(stored=True), content=TEXT) index_dir = "path_to_index_directory" ix = create_in(index_dir, schema) writer = ix.writer() writer.add_document(title="Introduction to Whoosh", content="Whoosh is a fast and featureful pure-Python search library.") writer.add_document(title="Getting Started with Whoosh", content="To get started with Whoosh, first install the library and then create an index.") writer.commit() searcher = ix.searcher() query = QueryParser("content", ix.schema).parse("library") results = searcher.search(query) for result in results: print(result['title'])


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