从搜索stackoverflow我发现使用xpath的解决方案允许不区分大小写的搜索。我最近对模式进行了一些更改,当我回到搜索时,在使用这种方法时我什么都没发现。这是我的架构:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="system">
<xs:complexType>
<xs:sequence>
<xs:element ref="pData"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="pData">
<xs:complexType>
<xs:sequence>
<xs:element ref="pNum"/>
<xs:element ref="sData"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="pNum" type="xs:integer"/>
<xs:element name="sData">
<xs:complexType>
<xs:sequence>
<xs:element ref="sNum"/>
<xs:element maxOccurs="unbounded" ref="hData"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sNum" type="xs:NMTOKEN"/>
<xs:element name="hData">
<xs:complexType>
<xs:sequence>
<xs:element ref="hTitle"/>
<xs:element ref="bData"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="hTitle" type="xs:string"/>
<xs:element name="bData">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="sitData"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sitData" >
<xs:complexType mixed="true">
<xs:sequence>
<xs:element ref="sitTitle"/>
<xs:element minOccurs="0" ref="sitInfo"/>
<xs:choice>
<xs:element ref="bothColumn"/>
<xs:sequence>
<xs:element ref="leftColumn"/>
<xs:element ref="rightColumn"/>
</xs:sequence>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sitTitle" type="xs:string"/>
<xs:element name="sitInfo" type="xs:string"/>
<xs:element name="bothColumn">
<xs:complexType>
<xs:sequence>
<xs:element ref="bothTitle"/>
<xs:element ref="bothInfo"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="bothTitle" type="xs:string"/>
<xs:element name="bothInfo" type="xs:string"/>
<xs:element name="leftColumn">
<xs:complexType>
<xs:sequence>
<xs:element ref="leftTitle"/>
<xs:element ref="leftInfo"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="leftTitle" type="xs:string"/>
<xs:element name="leftInfo" type="xs:string"/>
<xs:element name="rightColumn">
<xs:complexType>
<xs:sequence>
<xs:element ref="rightTitle"/>
<xs:element ref="rightInfo"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rightTitle" type="xs:string"/>
<xs:element name="rightInfo" type="xs:string"/>
</xs:schema>
所以我原来的搜索是:
return $doc/system/pData/sData/hData/bData/sitData[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),$searchTerm)]
所以当我搜索一个术语时会出现问题&#34; System&#34;当我知道那里存在数据时,什么都不会出现,但如果我搜索&#34; system&#34;所有版本的系统都会回来。我似乎无法找到这个问题的其他人,虽然搜索仍然对所有小写字母不区分大小写我感到困惑,并且想要了解我的xpath搜索现在发生了什么。我正在利用marklogic进行这些xpath调用。这是一个适合此模式的示例xml:
<system>
<pData>
<pNumber>908957303</pNumber>
<sData>
<sNumber>12345</sNumber>
<hData>
<hTitle>What to expect</hTitle>
<bData>
<sitData>
<sitTitle>A whole lot of fun</sitTitle>
<sitInfo> defined fun</sitInfo>
<leftColumn>
<leftTitle>to the left</leftTitle>
<leftInfo> all your clothes </leftInfo>
</leftColumn>
<rightColumn>
<rightTitle>to the right</rightTitle>
<rightInfo> right hand turns </rightInfo>
</rightColumn>
</sitData>
<sitData>
<sitTitle>we out here</sitTitle>
<sitInfo> doing this is painful </sitInfo>
<bothColumn>
<bothTitle>2001 was a good year</bothTitle>
<bothInfo>but it did have some downfalls</bothInfo>
</bothColumn>
</sitData>
</bData>
</hData>
<hData>
<hTitle>What to expect</hTitle>
<bData>
<sitData>
<sitTitle>A whole lot of fun</sitTitle>
<sitInfo> defined fun</sitInfo>
<leftColumn>
<leftTitle>to the left</leftTitle>
<leftInfo> all your clothes </leftInfo>
</leftColumn>
<rightColumn>
<rightTitle>to the right</rightTitle>
<rightInfo> right hand turns </rightInfo>
</rightColumn>
</sitData>
<sitData>
<sitTitle>we out here</sitTitle>
<sitInfo> doing this is painful </sitInfo>
<bothColumn>
<bothTitle>2001 was a good year</bothTitle>
<bothInfo>but it did have some downfalls</bothInfo>
</bothColumn>
</sitData>
</bData>
</hData>
</sData>
</pData>
</system>
答案 0 :(得分:3)
您已将MarkLogic添加为标记,因此,如果您使用的是MarkLogic,则可以利用其为以下内容设计的文本函数:
let $doc := ...
let $q := cts:word-query($searchTerm, "case-insensitive")
return $doc//sitData[cts:contains(., $q)]
这假设您希望匹配在字边界上。如果你真的希望“foo”匹配“food”,那么你可以使用通配符。