whoosh MultifieldParser字段搜索或查询解析器连接

2024-10-02 08:19:40 发布

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

我正在尝试使用whoosh在appengine上为我的blogapp添加搜索功能,但是我不理解一些东西。在

blog条目用titlecontentstatus字段建立索引。在

我想在公共页面上有不同类型的结果,然后在管理页面上,但不需要有多个索引。在

在frontpage上,我希望访问者能够只在titlecontent字段中搜索可见的条目,并且在管理员中我也希望搜索草稿条目。在

我是否可以使用QueryParser连接搜索,以便可以搜索多个字段?
我如何过滤状态:可见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)

Tags: searchadmintitleisstatusnot条目页面

热门问题