I have created an index and created documents as per documentation.
But when I am running the script do I always have to go through the process of adding the document and then search for the string.
Is it possible to store it once and then I can search for the terms again and again?
Once you've created an index, you can reuse that index (assuming you've saved it).
In Whoosh, you can reopen a previously-generated index like so:
import whoosh.index as index
ix = index.open_dir("dir/to/index")
Here, ix
is an Index
object. The file path is the same you used to create the index using create_in
. You can then create a Searcher
object (ix.searcher()
) and begin searching, just as you probably learned in the "Quick start".
See "How to index documents" for more information.