python
from whoosh.index import create_in, open_dir
from whoosh.fields import Schema, TEXT, ID
from whoosh.qparser import QueryParser
schema = Schema(id=ID(stored=True), content=TEXT(stored=True))
ix = create_in("path/to/index/directory", schema)
writer = ix.writer()
writer.commit()
ix = open_dir("path/to/index/directory")
qp = QueryParser("content", schema=ix.schema)
query = qp.parse(query_str)
searcher = ix.searcher()
results = searcher.search(query)
for result in results:
print(f"ID: {result['id']} Content: {result['content']}")