[英]“Query has no attribute 'whoosh_search” AttributeError in Flask + Whoosh + SQLAlchemy
[英]whoosh search query with converting '-' into AND
我正試圖用飛快移動進行文本搜索。
當我搜索包含-
(例如: 'IGF-1R'
)的字符串時,它最終會搜索'IGF'
和'1R'
,因此不會將其視為單個字符串。
知道為什么嗎?
這是我正在使用的代碼:
class MyFuzzyTerm(FuzzyTerm):
def __init__(self, fieldname, text, boost=1.0, maxdist=1, prefixlength=2, constantscore=True):
super(MyFuzzyTerm, self).__init__(fieldname, text, boost, maxdist, prefixlength, constantscore)
with ix.searcher() as searcher:
qp = QueryParser("gene", schema=ix.schema, termclass=MyFuzzyTerm)
q = qp.parse('IGF-1R')
q返回:
And([MyFuzzyTerm('gene', 'igf', boost=1.000000, maxdist=1, prefixlength=2), MyFuzzyTerm('gene', '1r', boost=1.000000, maxdist=1, prefixlength=2)])
我希望它是:
MyFuzzyTerm('gene', 'igf-1r', boost=1.000000, maxdist=1, prefixlength=2)
將文本分成單詞是tokenizer的工作,我通常使用whoosh.analysis.SpaceSeparatedTokenizer()
但是對於你的情況,tokenizer是基於空格和破折號分離的。
所以我想你正在使用的whoosh.analysis.CharsetTokenizer(charmap)
內用(空間,破折號) charmap
或whoosh.analysis.RegexTokenizer(expression=<_sre.SRE_Pattern object>, gaps=False)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.