Skip to navigation
Simplified whoosh example of indexing, listing and searching
23.11.21
async def whoosh_example(self): if os.path.exists("indexdir"): shutil.rmtree("indexdir") schema = Schema(key=ID(stored=True),content=TEXT(stored=True)) if not os.path.exists("indexdir"): os.mkdir("indexdir") ix = create_in("indexdir",schema) writer = ix.writer() for i in range(100): writer.add_document(key='key{}'.format(i),content='content{}'.format(i)) writer.commit() ix = open_dir("indexdir") with ix.searcher(weighting=scoring.Frequency) as searcher: print(list(searcher.lexicon("key"))) print(list(searcher.lexicon("content"))) parser = QueryParser("content", ix.schema) po = parser.parse(u"content1 OR content2 OR contentx") result = searcher.search(po) for i in result: print(dict(i)['key']) print(dict(i)['content'])
https://whoosh.readthedocs.io/en/latest/parsing.html
Reply
Anonymous
import os from whoosh.index import create_in from whoosh.fields import Schema, TEXT, ID from whoosh.qparser import QueryParser from whoosh import scoring from whoosh.index import open_dir from whoosh.query import * import shutil
23.11.21
Reply
Anonymous
Information Epoch 1732526919
Clarity is better than cleverness.
Home
Notebook
Contact us