I was looking a suggestion or preferably an example, to store or save the index of Whoosh. I am using Python 2.7 on Windows 7 Professional. If anyone may kindly help.
Asked
Active
Viewed 1,436 times
1 Answers
0
Whoosh is well documented , you can find most of things in the Official documentation. Here is the example of the Indexer-Searcher from the Quick Start:
# Indexer
>>> from whoosh.index import create_in
>>> from whoosh.fields import *
>>> schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)
>>> ix = create_in("indexdir", schema)
>>> writer = ix.writer()
>>> writer.add_document(title=u"First document", path=u"/a",
... content=u"This is the first document we've added!")
>>> writer.add_document(title=u"Second document", path=u"/b",
... content=u"The second one is even more interesting!")
>>> writer.commit()
# Searcher
>>> from whoosh.qparser import QueryParser
>>> with ix.searcher() as searcher:
... query = QueryParser("content", ix.schema).parse("first")
... results = searcher.search(query)
... results[0]
...
{"title": u"First document", "path": u"/a"}
The example is explained in details there.

Assem
- 11,574
- 5
- 59
- 97
-
1Thanks. I was looking to store the index and retrieve the index later to search. I used a slightly different method from whoosh.filedb.filestore import FileStorage if not os.path.exists("C:\Python27\IndexFiles\indexnew1"): os.mkdir("C:\Python27\IndexFiles\indexnew1") >>> storage3 = FileStorage("C:\Python27\IndexFiles\indexnew1") >>> ix = storage3.create_index(schema) >>> writer = ix.writer() seems going fine. – Searcher May 31 '15 at 11:37
-
@Searcher if this answered your question, mark it as `Accepted` – Assem May 31 '15 at 12:18
-
Sure. Thank you for a nice discussion and your kind time. – Searcher May 31 '15 at 12:26
-
@Searcher just a reminder for marking answer as accepted https://i.stack.imgur.com/uqJeW.png – Assem Jun 01 '15 at 10:26
-
Do I have to click anywhere? Where is that? Please suggest. I do not know. Regards. – Searcher Jun 01 '15 at 18:41
-
@Searcher Click on the good mark sign of my answer like in the image: https://i.stack.imgur.com/uqJeW.png . It will be green after clicking – Assem Jun 01 '15 at 21:38