繁体   English   中英

Python Whoosh不接受单个字符

[英]Python Whoosh not accepting single character

我正在尝试解析具有文本加数字的查询。

示例:Apple iphone 6结果:

  Results for And([Term('title', u'apple'), Term('title', u'iphone')])

而苹果iphone 62会导致:

  Results for And([Term('title', u'apple'), Term('title', u'iphone'), Term('title', u'62')])

为什么不接受一位数字?

默认情况下,所有带有单字符的单词在Whoosh中均被视为停用词,并被忽略。 这意味着将忽略所有字母和数字。

停用词是在处理自然语言数据(文本)之前或之后过滤掉的词。 (参考文献)

您可以检查StopFilter默认情况下是否将minsize = 2添加到预定义集中。

class whoosh.analysis.StopFilter(
        stoplist=frozenset(['and', 'is', 'it', 'an', 'as', 'at', 'have', 'in', 'yet', 'if', 'from', 'for', 'when', 'by', 'to', 'you', 'be', 'we', 'that', 'may', 'not', 'with', 'tbd', 'a', 'on', 'your', 'this', 'of', 'us', 'will', 'can', 'the', 'or', 'are']),
        minsize=2,
        maxsize=None,
        renumber=True,
        lang=None
        )

因此,您可以通过重新定义架构并删除StopFilter或将其与minsize = 1使用来解决此问题:

from whoosh.analysis import StandardAnalyzer
schema = Schema(content=TEXT(analyzer=StandardAnalyzer(stoplist=None)))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM