记录搜索查询格式
调用 PeerGroupSearchRecords 函数需要 XML 查询字符串参数,该参数用于确定搜索的基本条件。 使用以下架构来构建 XML 字符串:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="https://www.w3.org/2001/XMLSchema">
<xs:simpleType name="alphanumType">
<xs:restriction base="xs:string">
<xs:pattern value="\c+"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="operatorType">
<xs:choice maxOccurs="unbounded">
<xs:element ref="and" />
<xs:element ref="or" />
<xs:element ref="clause" />
</xs:choice>
</xs:complexType>
<xs:element name="and" type="operatorType"/>
<xs:element name="or" type="operatorType"/>
<xs:element name="clause">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="attrib" type="alphanumType" />
<xs:attribute name="type">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="string"/>
<xs:enumeration value="date"/>
<xs:enumeration value="int"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="compare" default="equal">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="equal"/>
<xs:enumeration value="greater"/>
<xs:enumeration value="less"/>
<xs:enumeration value="notequal"/>
<xs:enumeration value="greaterorequal"/>
<xs:enumeration value="lessorequal"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="peersearch">
<xs:complexType>
<xs:choice>
<xs:element ref="clause" />
<xs:element ref="and" />
<xs:element ref="or" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
要用于记录搜索的元素
记录搜索中的主元素是 对等搜索,其中包含 xmlns 属性中关联架构的统一资源标识符(URI)。 当 peersearch 用作子元素时,可以使用 和、子句以及 或 作为子元素。
和 - 和 元素对开始标记和结束标记中包含的一个或多个子句执行逻辑 AND作。 其他 和 和 或 标记可以是子级,其子子句的递归结果包含在作中。
例如,如果要获取包含名称等于 James Peters 的记录,以及大于 2003/28/2003 的上次更新或小于 2003/1/31 的创建日期,请使用以下 XML 查询字符串:
<?xml version="1.0" encoding="utf-8" ?> <peersearch xmlns:xs="https://www.w3.org/2001/XMLSchema"> <and> <clause attrib="peercreatorid" type="string" compare="equal">James Peters</clause> <or> <clause attrib="peerlastmodificationtime" type="date" compare="greater">2003-01-31</clause> <clause attrib="peercreationtime" type="date" compare="less">2003-02-328</clause> </or> </and> </peersearch>
子句 - 子句 元素指定一个基本比较规则,该比较规则将特定记录属性的值与开始标记和结束标记之间的值进行比较。 类型 和 比较 属性必须提供 比较 指示要执行的比较作。 例如,指示所有匹配记录的简单搜索必须具有等于 James Peters 的 peercreatorid 值,如下所示:
<?xml version="1.0" encoding="utf-8" ?> <peersearch xmlns:xs="https://www.w3.org/2001/XMLSchema"> <clause attrib="peercreatorid" type="string" compare="equal">James Peters</clause> </peersearch>
常见的 类型 属性包括 int、字符串和 日期。 日期 属性可以是 https://www.w3.org/TR/NOTE-datetime描述的标准日期格式之一。
比较 属性的值 相等、notequal、小于、、lessorequal和 greaterorequal。
- 或 - 或 元素对开始标记和结束标记中包含的一个或多个子句执行逻辑 OR作。 其他 或 和 和 元素可以是子元素,子子句的递归结果包含在作中。 例如,如果要获取包含名称等于 James Peters 的记录,或 2003 年 1 月 31 日到 2003 年 2 月 28 日之间的上次更新,请使用以下 XML 查询字符串:
<?xml version="1.0" encoding="utf-8" ?>
<peersearch xmlns:xs="https://www.w3.org/2001/XMLSchema">
<or>
<clause attrib="peercreatorid" type="string" compare="equal">James Peters</clause>
<and>
<clause attrib="peerlastmodificationtime" type="date" compare="greater">2003-01-31</clause>
<clause attrib="peerlastmodificationtime" type="date" compare="less">2003-02-28</clause>
</and>
</or>
</peersearch>
有关记录搜索的详细信息
peersearch 后的第一个节点级别 只能有一个元素。 但是,该元素的后续子级可以具有相同级别的多个元素。
以下搜索查询不正确:
<?xml version="1.0" encoding="utf-8" ?>
<peersearch xmlns:xs="https://www.w3.org/2001/XMLSchema">
<clause attrib="peercreatorid" type="string" compare="equal">James Peters</clause>
<and>
<clause attrib="peerlastmodificationtime" type="date" compare="greater">2003-01-31</clause>
<clause attrib="peerlastmodificationtime" type="date" compare="less">2003-02-28</clause>
</and>
</peersearch>
查询失败,因为为匹配返回两个值而不解析为一个 true/false 值,这意味着一个子句是查询等于 James Peters 的记录的名称,AND作与两个组件子句匹配。 结果是两个逻辑 true/false 值,这些值相互矛盾。
若要获取名称等于 James Peters 的所有记录,以及 2003/1/31 和 2/28/2003 之间的上次更新,请将 子句 和 和 标记放在打开和关闭 和 标记之间的同一级别。 以下示例显示了成功的查询:
<?xml version="1.0" encoding="utf-8" ?>
<peersearch xmlns:xs="https://www.w3.org/2001/XMLSchema">
<and>
<clause attrib="peercreatorid" type="string" compare="equal">James Peters</clause>
<and>
<clause attrib="peerlastmodificationtime" type="date" compare="greater">2003-01-31</clause>
<clause attrib="peerlastmodificationtime" type="date" compare="less">2003-02-28</clause>
</and>
</and>
</peersearch>
以下列表标识了编写成功查询时必须知道的其他特定信息:
- 、 和 或 标记不能位于打开和关闭 子句 标记之间,因为在配置中,它们被解释为要匹配的值的一部分,从而导致错误或失败的匹配。
- 每对 和 以及 或 打开和结束标记必须至少包含一个或多个子节点。
- 此架构中不允许有一组零个元素。
记录属性
通过使用 记录属性架构,用户可以在子句元素中指定的 attrib XML 属性创建记录属性。 通过将 pszAttributesPEER_RECORD 成员设置为 xml 字符串(使用架构中指定的格式)来添加新记录的属性。
对等基础结构保留以下属性名称:
- peerlastmodifiedby
- peercreatorid
- peerlastmodificationtime
- peerrecordid
- peerrecordtype
- peercreationtime
- peerlastmodificationtime
特殊字符
某些字符可用于表达匹配模式,或转义其他特殊字符。 下表描述了这些字符。
字符模式 | 描述 |
---|---|
* | 通配符。 在子句值中遇到此字符时,它将匹配任何值的 0-n 个字符,包括空格和非字母字符。 例如: “<子句 attrib=”peercreatorid“ type=”string“ compare=”equal“>James P*</clause>” 此子句匹配所有 peercreatorid 名称为“James”的值,以及以“P”开头的姓氏。 |
\* | 一个转义的星号。 此序列与星号字符匹配。 |
? | 单字符通配符。 在子句值中遇到此字符时,它将匹配任何单个字符,包括空格和非字母字符。例如: “<子句 attrib=”filename“ type=”string“ compare=”equal“>data-0?.xml</clause>” 此子句匹配 文件名 值,例如“data-01.xml”和“data-0B.xml”。 |
\? | 转义的问号。 此序列与问号字符匹配。 |
\\ | 一个转义的反斜杠。 此序列匹配单个反斜杠字符。 |
如果字符序列无效,则 PeerGroupSearchRecords 函数返回错误 E_INVALIDARG。 无效序列是包含“\”(反斜杠)字符的任何序列,该字符后跟“*”(星号)字符,即“?”(问号)字符,或其他“\”(反斜杠)字符。