2015-05-31 5 views
0

Я искал предложение или, желательно, пример, чтобы сохранить или сохранить индекс Whoosh. Я использую Python 2.7 для Windows 7 Professional. Если кто-то может любезно помочь.Сохранение индекса в Whoosh

ответ

0

Whoosh хорошо документирован, вы можете найти большинство вещей в Official documentation. Вот пример Индексатор-Searcher из 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"} 

пример объясняется в деталях there.

+0

Спасибо. Я искал, чтобы сохранить индекс и получить индекс позже для поиска. Я использовал немного другой метод из whoosh.filedest.filestore импортировал FileStorage, если не os.path.exists ("C: \ Python27 \ IndexFiles \ indexnew1"): \t os.mkdir ("C: \ Python27 \ IndexFiles \ indexnew1") >>> storage3 = FileStorage («C: \ Python27 \ IndexFiles \ indexnew1») >>> ix = storage3.create_index (схема) >>> writer = ix.writer() кажется, все в порядке. – Searcher

+0

Добро пожаловать, * все дороги ведут в Рим * –

+0

@Searcher, если это ответили на ваш вопрос, отметьте его как «Принято» –

Смежные вопросы