使用catalog在Plone中搜索内容
(转贴)介绍查询条件、元数据、使用方法、扩展方法等。
(转贴)介绍查询条件、元数据、使用方法、扩展方法等。
查询的组成部分:
ZCatalog
建立索引:(索引,用来构造查询条件)
Zcatalog不是返回对象,而是对象的Plugable Brains,Pluggable Brain包括Metadata和下面的信息:
- has_key(key)
- getPath()
- getURL() : 得到URL!!
- getObject() : 得到对象!!
- getRID()
查询使用
三种方法:
- 通过REQUEST对象:
- 命名参数:portal_catalog.searchResults(meta_type=
Document, sort_on=modified, sort_order=reverse) - 通过字典:portal_catalog({
meta_type:Document,Creator:panjy}) - 列表:Catalog(meta_type=[
DTML Method,ZCatalog]?) - 多个查询条件(AND/OR):http://www.zope.org/Members/k/ZCatalog_searchResults_note
- 使用Records的高级的Catalog使用方法:
- 关键字索引:
# big or shiny
results=Catalog(categories=['big, 'shiny'])
# big and shiny
results=Catalog(categories={'query':['big','shiny'],
'operator':'and'}) - Field索引:
# items modified in the last week
results=Catalog(bobobase_modification_time={
'query':DateTime() - 7,
'range': 'min'} # min/max/minmax
) - TestIndex / PathIndex 略
查询条件
- Creator
- FieldIndex 创建人
- Description
- ZCTextIndex 描述
- SearchableText
- ZCTextIndex 可查找的文本
- Subject
- KeywordIndex 关键字
- Title
- ZCTextIndex 标题
- allowedRolesAndUsers
- KeywordIndex 允许的角色和用户
- Date
- FieldIndex
- created
- FieldIndex 创建时间
- start
- FieldIndex 开始时间
- end
- FieldIndex 结束时间
- effective
- FieldIndex 生效时间
- expires
- FieldIndex 失效时间
- id
- FieldIndex 文档的ID(Name)
- in_reply_to
- FieldIndex 回复的ID号,None表示顶层
- modified
- FieldIndex 修改时间
- path
- PathIndex 路径(从根开始)
- portal_type
- FieldIndex CMF中的内容类型ID
- Type
- FieldIndex 内容类型的显示名称
- meta_type
- FieldIndex Zope的meta_type, 更底层。多个内容可能属于同一个meta_type
- review_state
- FieldIndex 评审(工作流)状态
可显示的元数据
CreationDate
Creator
Date
Description
EffectiveDate
ExpiresDate
ModificationDate
Subject
Title
Type
created
effective
end
expires
getIcon
getId
id
meta_type
modified
originals_puid
portal_type
puid
remote_url
review_state
start