我在MongoDB中建立了一個大型銀行數據庫。我可以輕鬆地獲取這些信息,並使用它在whoosh中創建索引。例如,我希望能夠匹配銀行名稱'Eagle Bank &密蘇里州信託公司'和'密蘇里州鷹行和信託公司'。下面的代碼工作與簡單的模糊等,但不能達到上述匹配:模糊字符串在Python中用Whoosh搜索
from whoosh.index import create_in
from whoosh.fields import *
schema = Schema(name=TEXT(stored=True))
ix = create_in("indexdir", schema)
writer = ix.writer()
test_items = [u"Eagle Bank and Trust Company of Missouri"]
writer.add_document(name=item)
writer.commit()
from whoosh.qparser import QueryParser
from whoosh.query import FuzzyTerm
with ix.searcher() as s:
qp = QueryParser("name", schema=ix.schema, termclass=FuzzyTerm)
q = qp.parse(u"Eagle Bank & Trust Co of Missouri")
results = s.search(q)
print results
給我:
<Top 0 Results for And([FuzzyTerm('name', u'eagle', boost=1.000000, minsimilarity=0.500000, prefixlength=1), FuzzyTerm('name', u'bank', boost=1.000000, minsimilarity=0.500000, prefixlength=1), FuzzyTerm('name', u'trust', boost=1.000000, minsimilarity=0.500000, prefixlength=1), FuzzyTerm('name', u'co', boost=1.000000, minsimilarity=0.500000, prefixlength=1), FuzzyTerm('name', u'missouri', boost=1.000000, minsimilarity=0.500000, prefixlength=1)]) runtime=0.00166392326355>
是否有可能實現什麼,我想嗖?如果沒有其他基於python的解決方案,我有嗎?
不錯的一個,謝謝 – cedbeu