我正在尝试使用whoosh将搜索功能添加到我在 appengine 上的 blogapp 中,但我不明白一些东西。
title
博客条目使用和字段content
进行索引。status
我想在公共页面和管理页面上有不同类型的结果,但不需要多个索引。
在首页上,我希望访问者能够仅在和字段上搜索可见条目,并且在管理员中我还希望搜索草稿条目。title
content
我可以使用连接搜索,QueryParser
以便可以搜索多个字段吗?
我如何过滤status:visible with MultifieldParser
?
编辑
还没有测试它,但我在 whoosh 邮件列表上得到了答案:
# Create a parser that will search in title and content
qp = qparser.MultifieldParser(["title", "content"], ix.schema)
# Parse the user query
q = qp.parse(user_query_string)
# If request is not admin, filter on status:visible
filterq = query.Term("status", u"visible") if not is_admin else None
# Get search results
results = searcher.search(q, filter=filterq)