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

Ryan Dew ryan.j.dew at gmail.com
Wed Mar 28 07:29:16 PDT 2012


Not sure this will fix everything for you, but you might want to change
cts:element-value-query(xs:QName("id"),"*")  to
cts:element-value-query(xs:QName("id"),"*",
"unwildcarded") or  cts:element-value-query(xs:QName("id"),"*", "exact") since
* is a wildcard character.

On Wed, Mar 28, 2012 at 8:16 AM, Sudheer Yalaverthi <
sudheer.yalaverthi at gmail.com> wrote:

> I am using search:search. I need to make an additional query satisfying
> this condition.
>
> I can not make use of xpath here.
>
>
> On Wed, Mar 28, 2012 at 1:53 AM, VISH RAJPUT <svishnu.singh4 at gmail.com>wrote:
>
>> Hi Sudheer,
>>
>> You can use xpath expression with predicate like
>>
>> *//entrylist/entry[identity/id/text()='*' and
>> not(permissionList/permission='read')]*
>>
>>  to test the below highlighted.
>>
>> Regards,
>> Vishnu
>>
>>
>> On Wed, Mar 28, 2012 at 12:19 AM, Sudheer Yalaverthi <
>> sudheer.yalaverthi at gmail.com> wrote:
>>
>>> Hi Damon,
>>>
>>> I have made the xml simple.
>>> <entrylist>
>>>
>>>     <entry type="deny">
>>>         <identity>
>>>             <id>*</id>
>>>         </identity>
>>>         <permissionList>
>>>             <permission>read</permission>
>>>             <permission>write</permission>
>>>         </permissionList>
>>>     </entry>
>>>     <entry type="deny">
>>>         <identity>
>>>             <id>123</id>
>>>
>>>         </identity>
>>>         <permissionList>
>>>             <permission>write</permission>
>>>         </permissionList>
>>>     </entry>
>>> </entrylist>
>>>
>>> There will be 'n' number of xmls like the above in the DB. I need to
>>> retrieve the xml under two conditions.
>>> 1. id = 123 and entry should have read permission in the permission list
>>>  2. id = * and entry should not have the read permission in it
>>>
>>> I am able to form a query for the first condition. But i could not make
>>> the second condition.
>>>
>>>
>>> Thanks,
>>> Sudheer
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Sun, Mar 25, 2012 at 9:09 AM, Damon Feldman <
>>> Damon.Feldman at marklogic.com> wrote:
>>>
>>>> Sudheer,****
>>>>
>>>> ** **
>>>>
>>>> Can you post a self-contained, minimal example that runs in
>>>> queryConsole? By this I mean a document insert or two and a query that
>>>> shows the problem. Ideally, you would simplify the query and document to
>>>> the simplest example that shows the behavior you are seeing, perhaps a
>>>> single permission and two notes will work.****
>>>>
>>>> ** **
>>>>
>>>> This allows people to paste it into queryConsole and immediately see
>>>> your problem, then try solutions.****
>>>>
>>>> ** **
>>>>
>>>> Yours,****
>>>>
>>>> Damon****
>>>>
>>>> ** **
>>>>
>>>> *From:* general-bounces at developer.marklogic.com [mailto:
>>>> general-bounces at developer.marklogic.com] *On Behalf Of *Sudheer
>>>> Yalaverthi
>>>> *Sent:* Friday, March 23, 2012 4:23 PM
>>>> *To:* MarkLogic Developer Discussion
>>>> *Subject:* Re: [MarkLogic Dev General] Problem in making use of
>>>> cts:not-query()****
>>>>
>>>> ** **
>>>>
>>>> John,
>>>>
>>>> i have tried this. But still this is not helping me.
>>>> I am putting my exact xml , scenario.
>>>>
>>>> Xml in DB :
>>>>
>>>> <notelist>
>>>>     <note>
>>>>         <text>this is my first note</text>
>>>>         <accessControl>
>>>>             <explicitAccessControlList>
>>>>                 <entry type="deny">
>>>>                     <identity>
>>>>                         <id>*</id>
>>>>                     </identity>
>>>>                     <permissionList>
>>>>                         <permission>read</permission>
>>>>                         <permission>write</permission>
>>>>                         <permission>delete</permission>
>>>>                         <permission>write-acl</permission>
>>>>                     </permissionList>
>>>>                 </entry>
>>>>                 <entry type="allow">
>>>>                     <identity>
>>>>                         <id>1111</id>
>>>>                     </identity>
>>>>                     <permissionList>
>>>>                         <permission>read</permission>
>>>>                         <permission>write</permission>
>>>>                         <permission>delete</permission>
>>>>                         <permission>write-acl</permission>
>>>>                     </permissionList>
>>>>                 </entry>
>>>>             </explicitAccessControlList>
>>>>         </accessControl>
>>>>     </note>
>>>>     <note>
>>>>         <note>
>>>>             <text>this is my second note</text>
>>>>             <accessControl>
>>>>                 <explicitAccessControlList>
>>>>                     <entry type="deny">
>>>>                         <identity>
>>>>                             <id>*</id>
>>>>                         </identity>
>>>>                         <permissionList>
>>>>                             <permission>write</permission>
>>>>                             <permission>delete</permission>
>>>>                         </permissionList>
>>>>                     </entry>
>>>>                     <entry type="allow">
>>>>                         <identity>
>>>>                             <id>1111</id>
>>>>                         </identity>
>>>>                         <permissionList>
>>>>                             <permission>read</permission>
>>>>                             <permission>write</permission>
>>>>                             <permission>delete</permission>
>>>>                         </permissionList>
>>>>                     </entry>
>>>>                 </explicitAccessControlList>
>>>>             </accessControl>
>>>>         </note>
>>>> </notelist>
>>>>
>>>>
>>>> There will be so many xmls like this in the DB. My requirement is i
>>>> have to retrieve this xml if i have a note element which has my qstring in
>>>> the text, and has an entry(type=allow with my id, read permission) or an
>>>> entry(type= deny, id = *, should not have read permission in that).
>>>>
>>>> Below is the query i am trying.
>>>>
>>>>  cts:element-query(
>>>>                     xs:QName("note"),
>>>>                     cts:and-query((
>>>>                             cts:element-word-query( xs:QName("text"),
>>>> $qstring, "case-insensitive"),
>>>>                             cts:element-query(
>>>>                                   xs:QName("accessControl"),
>>>>                                   cts:element-query(
>>>>
>>>> xs:QName("explicitAccessControlList"),
>>>>
>>>> cts:or-query((
>>>>                                             cts:element-query(
>>>>                                                 xs:QName("entry"),
>>>>
>>>> cts:and-query((
>>>>                                                     cts:element-query(
>>>>
>>>> xs:QName("identity"),
>>>>
>>>> cts:element-value-query(xs:QName("id"),$user-id)
>>>>                                                      ),
>>>>
>>>> cts:element-attribute-value-query(xs:QName("entry"), xs:QName("type"),
>>>> "allow") ,
>>>>
>>>> cts:element-value-query(xs:QName("permission"),"read"
>>>> )
>>>>                                                 ))
>>>>                                              )
>>>>
>>>> ,
>>>>                                              cts:element-query(
>>>>
>>>> xs:QName("entry"),
>>>>                                                 cts:and-query((
>>>>                                                     cts:element-query(
>>>>
>>>> xs:QName("identity"),
>>>>
>>>> cts:element-value-query(xs:QName("id"),"*")
>>>>
>>>> ),
>>>>
>>>> cts:element-attribute-value-query(xs:QName("entry"), xs:QName("type"),
>>>> "deny")
>>>>
>>>> ,
>>>>
>>>> cts:element-range-query(xs:QName("permission"), "!=", "read", "collation=
>>>> http://marklogic.com/collation/"
>>>> )
>>>>                                                 ))
>>>>
>>>> )
>>>>                                         ))
>>>>                                   )
>>>>                             )
>>>>                     ))
>>>>               )
>>>>
>>>>
>>>> I am still not able to get the expected results. :(
>>>>
>>>>
>>>>
>>>> Thanks,
>>>> Sudheer ****
>>>>
>>>> On Fri, Mar 23, 2012 at 12:48 PM, John Zhong <john at yuxipacific.com>
>>>> wrote:****
>>>>
>>>> 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****
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> General mailing list
>>>> General at developer.marklogic.com
>>>> http://developer.marklogic.com/mailman/listinfo/general****
>>>>
>>>> ** **
>>>>
>>>> _______________________________________________
>>>> General mailing list
>>>> General at developer.marklogic.com
>>>> http://developer.marklogic.com/mailman/listinfo/general
>>>>
>>>>
>>>
>>> _______________________________________________
>>> General mailing list
>>> General at developer.marklogic.com
>>> http://developer.marklogic.com/mailman/listinfo/general
>>>
>>>
>>
>> _______________________________________________
>> General mailing list
>> General at developer.marklogic.com
>> http://developer.marklogic.com/mailman/listinfo/general
>>
>>
>
> _______________________________________________
> 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/20120328/36231a2c/attachment-0001.html 


More information about the General mailing list