It took me a lil while to get to this working..it needs more attention where
ever there are commas
I agree with you this is a dirty way to do it.. I wish I could write a
utility that would take care of such stuff..

declare namespace ns = "http://addware.com/xmlschemas/report/1";;

let $fragment := "//ns:address"

let $expression := fn:concat('cts:search(',
$fragment,
',cts:and-query((cts:document-query("doc.xml")',
',cts:element-range-query(xs:QName("ns:name")',
',"="',
',"John Doe")))',
',"unfiltered")'
)

return xdmp:value($expression)



On Thu, Feb 17, 2011 at 6:42 PM, Abishek N <[email protected]> wrote:

> Hello
> I know this sounds quite simple, but I have not been able to accomplish
> this.
> Let me consider the following eg.  I am trying to run a search on a single
> document on the fragament root
> //ns:address
>
> xquery version "1.0-ml";
> declare namespace ns = "http://www.addware.com/xmlschemas/report/1";;
>
>
> let $result :=
> cts:search(//ns:address,
> cts:and-query((
> cts:document-query("doc.xml"),
> ((cts:element-range-query(xs:QName("ns:name"),"=","John
> Doe"))))),'unfiltered')
>
>
> similarly based on the request if i were to run the search based on the
> user name in various fragament roots
> for eg //ns:insurance  or //ns:contactnumber based on the user name can I
> parameterize the fragament root
> //ns:address such that I dont have to write multiple search queries?
>
> here is what I tried, lets say I have a metadata xml file which tells be if
> the request is for
> "ad", then look for the results in the fragament roots //ns:address
> if it for  "phone", then look for results in the fragament root
> //ns:contactnumber which would be returned as a xs:string
> even though I read it from the metadata file, when I do an unquote it tells
> me that this is not a searchable
> expression.
> metadata file would be like this
> <list>
>     <frags>
>         <type>ad</type>
>         <searchfrag>//ns:address</searchfrag>
>     </frags>
>     <frags>
>         <type>phone</type>
>         <searchfrag>//ns:contactnumber</searchfrag>
>     </frags>
>     <frags>
>         <type>ins</type>
>         <searchfrag>//ns:insurance</searchfrag>
>     </frags>
> </list>
>
>
> let $result :=
> cts:search(xdmp:unquote("//ns:address"),
> cts:and-query((
> cts:document-query("doc.xml"),
> ((cts:element-range-query(xs:QName("ns:name"),"=","John
> Doe"))))),'unfiltered')
>
> i found an another way
>
>
> let $result :=
> cts:search(if($attr="ad") then //ns:address else if ($attr="phone") then
> //ns:contactnumber else //ns:insurance,
> cts:and-query((
> cts:document-query("doc.xml"),
> ((cts:element-range-query(xs:QName("ns:name"),"=","John
> Doe"))))),'unfiltered')
>
>
>
> --
> Regards Abishek
>



-- 
Regards Abishek
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to