【发布时间】:2020-07-23 15:15:58
【问题描述】:
我正在使用 whoosh 来索引和搜索我的文档。我开发了一个 multi=field 搜索,但我想指定一些“MUST”字段。
我想要的是:我在搜索带有查询 q1 的书时,它会搜索标题和摘要,但我想指定一些过滤器,例如 autor= '作者姓名' 和 category= "books category" .
结果必须考虑到两个“必须”字段并搜索另外两个。
感谢您的帮助
【问题讨论】:
标签: whoosh
我正在使用 whoosh 来索引和搜索我的文档。我开发了一个 multi=field 搜索,但我想指定一些“MUST”字段。
我想要的是:我在搜索带有查询 q1 的书时,它会搜索标题和摘要,但我想指定一些过滤器,例如 autor= '作者姓名' 和 category= "books category" .
结果必须考虑到两个“必须”字段并搜索另外两个。
感谢您的帮助
【问题讨论】:
标签: whoosh
您可以在这种情况下使用 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 运算符搜索所有字段。根据您的需要,您可以自定义它们。更多关于运营商here 如and not 等。
【讨论】: