[MarkLogic Dev General] Problem in making use of cts:not-query()

John Zhong john at yuxipacific.com
Fri Mar 23 09:48:45 PDT 2012


You can change your
cts:not-query(cts:element-value-query(xs:QName("subject"), "C")) to
cts:element-range-query(xs:QName("subject"), "!=","C"), which needs the
"Element Range Indexes" on subject element.

So,

cts:element-query(
      xs:QName("user"),
      cts:and-query((
        cts:element-value-query(xs:QName("id"), "222"),
        cts:element-attribute-value-query(xs:QName("user"),
xs:QName("branch"), "CSE"),
        cts:element-range-query(xs:QName("subject"), "!=","C")
      ))
)

It worked for me on ML 4.2 version.

The cts:not-query does not work, in my opinion, it is because:

In your sample XML:

/userdetails//subject = "C"
> true

not(/userdetails//subject = "C")
> false

So, I think the cts:not-query works similarly...

BTW, I tried the solution mentioned by Geert, to define the user as
fragment root, but it did not work.

John

On Fri, Mar 23, 2012 at 4:48 AM, Sudheer Yalaverthi <
sudheer.yalaverthi at gmail.com> wrote:

> Hi Team,
>
> My sample XML would be like this.
>
> <userdetails>
>     <user branch="CSE">
>         <id>111</id>
>         <subjectList>
>             <subject>C</subject>
>             <subject>C++</subject>
>             <subject>Oracle</subject>
>         </subjectList>
>     </user>
>     <user branch="CSE">
>         <id>222</id>
>         <subjectList>
>             <subject>C++</subject>
>             <subject>Oracle</subject>
>         </subjectList>
>     </user>
>     <user branch="IT">
>         <id>333</id>
>         <subjectList>
>             <subject>C</subject>
>             <subject>C++</subject>
>             <subject>Oracle</subject>
>         </subjectList>
>     </user>
> </userdetails>
>
>
> I have a requirement where i should pick this Xml from the DB if there is
> a user entry with branch as"CSE" and id =222 and it should not have "C" as
> subject.
>
> If i write a additional query something like below for search:search()
> cts:element-query(
>       xs:QName("user"),
>       cts:and-query((
>       cts:element-value-query(xs:QName("id"), "222"),
>       cts:element-attribute-value-query(xs:QName("user"),
> xs:QName("branch"), "CSE"),
>       cts:not-query(cts:element-value-query(xs:QName("subject"), "C"))
>       ))
> )
>
> This is not turning me up the results. The only one scenario this query is
> gonna return back the result is if none of the users in the DB has the
> subject as "C". but this is not i am expecting. I know there is one user
> element which satisfies all the conditions and other user elements which
> fail these connditions. I want to retrieve the Xml even if one of the user
> element passes all these conditions irrespective of other elements pass or
> fail. Please suggest me.
> I am using search:search and i can not avoid this as i have some other
> requirements to sorting the result Xmls.
>
>
> Thanks,
> Sudheer
>
>
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20120324/789fd56a/attachment.html 


More information about the General mailing list