pip install whoosh
python
from whoosh.index import create_in
from whoosh.fields import Schema, TEXT
schema = Schema(content=TEXT(stored=True))
indexdir = 'path/to/index'
ix = create_in(indexdir, schema)
writer = ix.writer()
writer.commit()
python
from whoosh.qparser import QueryParser
from whoosh import scoring
ix = open_dir('path/to/index')
parser = QueryParser("content", schema=ix.schema)
query = parser.parse(search_query)
with ix.searcher(weighting=scoring.BM25F()) as searcher:
results = searcher.search(query, limit=10)
for result in results:
print(result)