Lets say given file a.txt:
hello world
good morning world
good night world
Given the keyword that I want to search is morning, I want to use whoosh python library to return the line that matches the keyword morning in the text file a.txt. So, it will return good morning world. How can I achieve this?
Update: Here is my schema:
schema = Schema(title=TEXT(stored=True),
path=ID(stored=True),
content=TEXT(stored=True))
then I add a writer add_document to content field
Index the text file per line and store the line number as a
NUMERICfield and the entire line as anIDfield (storage is cheap, right!).Something like the following (untested):
Clearly you could extend this to index multiple text files: