如何使用whoosh搜索关键字

2024-06-07 13:22:00 发布

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

项目架构:

下面是我创建的文章架构。在

class ArticleSchema(SchemaClass):
    title = TEXT(
        phrase=True, sortable=True, stored=True,
        field_boost=2.0, spelling=True, analyzer=StemmingAnalyzer())
    keywords = KEYWORD(
        commas=True, field_boost=1.5, lowercase=True)
    authors = KEYWORD(stored=True, commas=True, lowercase=True)
    content = TEXT(spelling=True, analyzer=StemmingAnalyzer())
    summary = TEXT(spelling=True, analyzer=StemmingAnalyzer())
    published_time = DATETIME(stored=True, sortable=True)
    permalink = STORED
    thumbnail = STORED
    article_id = ID(unique=True, stored=True)
    topic = TEXT(spelling=True, stored=True)
    series_id = STORED
    tags = KEYWORD(commas=True, lowercase=True)

搜索查询

^{pr2}$

当我尝试的标题搜索是有效的,但对作者和关键字的搜索不起作用。我不明白我在这里做错了什么。我从api获取数据,然后运行索引。一切正常。但是当我搜索像authorskeywords这样的关键字时,它就不起作用了。在


Tags: texttruefield架构analyzerkeywordboostkeywords
1条回答
网友
1楼 · 发布于 2024-06-07 13:22:00

authors和{}都属于{}类型,不支持短语搜索,这意味着您应该使用确切的关键字或其派生词之一进行搜索,因为您使用的是词干分析器。在

对于authors,我认为您应该使用TEXT。在

从whoosh文档中

whoosh.fields.KEYWORD

This type is designed for space- or comma-separated keywords. This type is indexed and searchable (and optionally stored). To save space, it does not support phrase searching.

相关问题 更多 >

    热门问题