Я пытаюсь протестировать Whoosh для поиска текста, и прямо сейчас простой надуманный пример у меня не работает. Я предполагаю, что я что-то упускаю здесь. В следующем коде я ожидаю, что он даст один результат поиска, но я получаю 0 совпадений.
import sys
import os
from whoosh.fields import Schema, TEXT, STORED
from whoosh.index import create_in, open_dir
from whoosh.query import *
#creating the schema
schema = Schema(tax_id=STORED,
name=TEXT(stored=True))
#creating the index
if not os.path.exists("index"):
os.mkdir("index")
ix = create_in("index",schema)
ix = open_dir("index")
writer = ix.writer()
writer.add_document(tax_id="17",name=u"Methyliphilus methylitrophus")
writer.add_document(tax_id="17",name=u"Methylophilus methylotrophus Jenkins et al. 1987")
writer.add_document(tax_id="45",name=u"Chondromyces lichenicolus")
writer.commit()
myquery = And([Term("name",u"Chondromyces")])
with ix.searcher() as searcher:
print searcher.search(myquery)
Выход:
<Top 0 Results for And([Term('name', u'Chondromyces lichenicolus')]) runtime=9.41753387451e-05>
Спасибо!