记录搜索查询格式

调用 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 - 元素对开始标记和结束标记之间的一个或多个子句执行逻辑 AND 操作。 其他 和 或 标记可以是子级,其子子句的递归结果包含在操作中。

    例如,如果要获取包含名称等于 James Peters 的记录,以及大于 2003 年 2 月 28 日或创建日期小于 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>
    
  • clause - 子句 元素指定一个基本比较规则,该规则将特定记录属性的值与开始标记和结束标记之间的值进行比较。 必须提供类型和比较属性 compare 指示要执行的比较操作。 例如,指示所有匹配记录的 peercreatorid 值必须等于 James Peters 的简单搜索显示在 XML 查询字符串中,如下所示:

    <?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>
    

    常见 类型 属性包括 intstringdate日期属性可以是中所述https://www.w3.org/TR/NOTE-datetime的标准日期格式之一。

    compare 属性的值为 equalnotequallessgreaterlessorequalgreaterorequal

  • or - 元素对开始标记和结束标记之间包含的一个或多个子句执行逻辑 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>

对等搜索后的第一级节点只能有一个元素。 但是,该元素的后续子级可以具有同一级别的多个元素。

以下搜索查询不正确:

<?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 日和 2003 年 2 月 28 日之间的上次更新,请将 子句和 和 标记置于开始和结束 标记之间的相同级别。 以下示例显示了成功的查询:

<?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 属性指定的记录属性。 通过使用架构中指定的格式将 PEER_RECORDpszAttributes 成员设置为 XML 字符串来添加新记录的属性。

对等基础结构保留以下属性名称:

  • peerlastmodifiedby
  • peercreatorid
  • peerlastmodificationtime
  • peerrecordid
  • peerrecordtype
  • peercreationtime
  • peerlastmodificationtime

特殊字符

某些字符可用于表示匹配模式,或转义其他特殊字符。 下表描述了这些字符。

字符模式 说明
* 通配符。 当子句值中遇到此字符时,它将匹配任何值的 0-n 个字符,包括空格和非字母数字字符。 例如:
“<clause attrib=”peercreatorid“ type=”string“ compare=”equal“>James P*</clause>”
此子句匹配名字为“James”且姓氏以“P”开头的所有 peercreatorid 值。
\* 一个转义的星号。 此序列与星号字符匹配。
? 单字符通配符。 当子句值中遇到此字符时,它将匹配任何单个字符,包括空格和非字母数字字符。例如:
“<clause attrib=”filename“ type=”string“ compare=”equal“>data-0?.xml</clause>”
此子句匹配 文件名 值,如“data-01.xml”和“data-0B.xml”。
\? 转义的问号。 此序列与问号字符匹配。
\\ 转义的反斜杠。 此序列匹配单个反斜杠字符。

如果字符序列无效, PeerGroupSearchRecords 函数 将返回错误E_INVALIDARG。 无效序列是包含“\” (反斜杠) 字符的任何序列,后跟不紧跟“*” (星号) 字符、“?” (问号) 字符或另一个“\” (反斜杠) 字符。