-1
我有這個代碼片段:排序蟒蛇嗖導致
from whoosh import index, qparser
def find(text, indexDir, _doc_schema):
parser = qparser.QueryParser("content", schema=_doc_schema, termclass=FuzzyTerm)
query = parser.parse(text)
index = index.open_dir(indexDir)
with index.searcher() as searcher:
for res in searcher.search(query, limit=limit, terms=True):
result = {
"classname": res["classname"],
"code": res["code"],
}
if highlights:
result["text"] = res.highlights("content")
print "Res ", result['text']
print "Matched terms ", res.matched_terms()
yield result
有沒有一種辦法,而搜索我matched_terms通過相關級別排序?所以,如果我在尋找'aaa',我希望術語'aaa'先來,但它們可能會在'aab'結果後出現。
您想排列結果或僅比條件嗎? –
'打印「匹配的術語」,排序(res.matched_terms())' –
bigOTHER,是的,我想排序結果,我又壞了。 – Sht0p0r