Tôi đã xây dựng một cơ sở dữ liệu lớn của các ngân hàng trong MongoDB. Tôi có thể dễ dàng lấy thông tin này và tạo các chỉ mục với nó trong whoosh. Ví dụ: tôi muốn có thể khớp tên ngân hàng 'Eagle Bank & Trust Co Missouri' và 'Eagle Bank and Trust Company of Missouri'. Các mã sau đây làm việc với đơn giản mờ như vậy, nhưng không thể đạt được một trận đấu trên trên:Chuỗi mờ Tìm kiếm bằng Whoosh bằng Python
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
mang lại cho tôi:
<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>
Có thể đạt được những gì tôi muốn với bất ngờ tới thăm? Nếu tôi không có giải pháp dựa trên python nào khác?
đẹp một, nhờ – cedbeu