我试着用嗖嗖声做文本搜索。你知道吗
当我搜索包含-
(例如:'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)
将文本拆分为单词是标记器的工作,我通常使用
whoosh.analysis.SpaceSeparatedTokenizer()
,但对于您的情况,标记器是基于空格和破折号进行拆分的。所以我打赌你是用
whoosh.analysis.CharsetTokenizer(charmap)
和charmap
内的(空格,破折号)或whoosh.analysis.RegexTokenizer(expression=<_sre.SRE_Pattern object>, gaps=False)
。你知道吗相关问题 更多 >
编程相关推荐