运行这段代码时,我不会对我放入查询字符串的任何部分匹配产生影响。例如" Methyl"并没有返回任何点击,但整个单词,如" Jenkins"做。有人可以指出这个问题,这可能是我做的事情,因为我第一次使用嗖嗖声。我基本上希望能够在字符串中的任何位置上的任何三个连续字符集中实现部分匹配。
import sys
import os
from whoosh.fields import Schema, TEXT, STORED
from whoosh.index import create_in, open_dir
#from whoosh.query import *
from whoosh.qparser import QueryParser
from whoosh.query import FuzzyTerm
#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:
query = QueryParser("name", ix.schema, termclass = FuzzyTerm).parse(u"Methyl")
results = searcher.search(query)
for i in results:
print i['name']
print i['tax_id']