将“”转换为和的快速搜索查询

2024-09-27 20:16:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着用嗖嗖声做文本搜索。你知道吗

当我搜索包含-(例如:'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)

Tags: 字符串textselfinitfieldnameixboostgene
1条回答
网友
1楼 · 发布于 2024-09-27 20:16:12

将文本拆分为单词是标记器的工作,我通常使用whoosh.analysis.SpaceSeparatedTokenizer(),但对于您的情况,标记器是基于空格和破折号进行拆分的。
所以我打赌你是用whoosh.analysis.CharsetTokenizer(charmap)charmap内的(空格,破折号)或whoosh.analysis.RegexTokenizer(expression=<_sre.SRE_Pattern object>, gaps=False)。你知道吗

相关问题 更多 >

    热门问题