【问题标题】:Multi-field search whoosh with field filters带有字段过滤器的多字段搜索嗖嗖声
【发布时间】:2020-07-23 15:15:58
【问题描述】:

我正在使用 whoosh 来索引和搜索我的文档。我开发了一个 multi=field 搜索,但我想指定一些“MUST”字段。

我想要的是:我在搜索带有查询 q1 的书时,它会搜索标题和摘要,但我想指定一些过滤器,例如 autor= '作者姓名' 和 category= "books category" .

结果必须考虑到两个“必须”字段并搜索另外两个。

感谢您的帮助

【问题讨论】:

    标签: whoosh


    【解决方案1】:

    您可以在这种情况下使用 whooshMultifieldParser

    from whoosh.qparser import MultifieldParser
    
    fields = ["title", "summary", "author", "category"]
    
    query = MultifieldParser(fields, schema=idx.schema, group=qparser.OrGroup).parse(q1)
    with idx.searcher() as searcher:
        results = searcher.search(query, limit=limit)
        ...........
    

    上面使用 Or Group 将使用 or 运算符搜索所有字段。根据您的需要,您可以自定义它们。更多关于运营商hereand not 等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-30
      • 2012-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多