见 correcting errors in user queries .
此模块包含用于更正用户查询中输入错误的帮助程序函数。
whoosh.spelling.
Corrector
¶拼写更正对象的基类。具体的子类应该实现 _suggestions
方法。
suggest
(text, limit=5, maxdist=2, prefix=0)¶参数: |
|
---|
whoosh.spelling.
ReaderCorrector
(reader, fieldname, fieldobj)¶根据读者中字段的内容建议更正。
按编辑距离排列建议,然后按最高频率到最低频率排列建议。
whoosh.spelling.
MultiCorrector
(correctors, op)¶合并子更正器列表中的建议。
whoosh.spelling.
QueryCorrector
(fieldname)¶用于更正用户查询中单词的对象的基类。
correct_query
(q, qstring)¶返回A Correction
对象,表示给定查询的正确形式。
参数: |
|
---|---|
返回类型: |
whoosh.spelling.
SimpleQueryCorrector
(correctors, terms, aliases=None, prefix=0, maxdist=2)¶基于字段名到的映射的简单查询更正器 Corrector
对象和 ("fieldname", "text")
要更正的元组。查询中出现在术语元组列表中的术语将使用适当的更正器进行更正。
参数: |
|
---|
whoosh.spelling.
Correction
(q, qstring, corr_q, tokens)¶表示用户查询字符串的正确版本。具有以下属性:
query
whoosh.query.Query
对象。string
original_query
whoosh.query.Query
已更正的对象。original_string
tokens
您也可以使用 Correction.format_string()
方法使用 whoosh.highlight.Formatter
班级。例如,要将更正后的查询字符串显示为HTML,并强调更改后的单词:
from whoosh import highlight
correction = mysearcher.correct_query(q, qstring)
hf = highlight.HtmlFormatter(classname="change")
html = correction.format_string(hf)