It sounds like you're looking for the 'searchable-expression' option. Try something like this. Note that namespaces can be a little chatty with the search API, but I'm not sure if that can be helped without changes to XQuery.
-- Mike declare namespace ns="ns"; import module namespace search="http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; search:resolve-nodes( document { cts:and-query( (cts:directory-query("/metadata/", "1"), cts:element-value-query( xs:QName("ns:status"), "New", "exact"), cts:element-value-query( xs:QName("ns:user"), "Ed", "exact"), cts:element-value-query( xs:QName("ns:doc-id"), "1234", "exact"))) }/*, <options xmlns="http://marklogic.com/appservices/search"> <searchable-expression xmlns:ns="ns">/ns:metadata</searchable-expression> <sort-order type="xs:string" collation="http://marklogic.com/collation/" direction="ascending"> <element ns="my-namespace" name="my-element"/> <annotation>some user comment can go here</annotation> </sort-order> <sort-order direction="ascending"> <score/> </sort-order> </options>) On 27 Mar 2013, at 22:07 , "Tim" <[email protected]> wrote: > Hi Mike, et al, > > Looking into this a little more, I'm still not sure how to create the query > for this approach. I have a cts:search that looks like this: > > cts:search( > /ns:metadata, > cts:and-query(( > cts:directory-query("/metadata/", "1"), > cts:element-value-query(xs:QName("ns:status"), "New", > "exact"), > cts:element-value-query(xs:QName("ns:user"), "Ed", "exact"), > cts:element-value-query(xs:QName("ns:doc-id"), > "1234", "exact") > )) > ) > > Here are some questions: > > 1. How do I retain the expression part of the cts:search in the query? > 2. How do I represent the query, merely by assigning the query to a > variable? For example, would I do the following? > > $query := cts:and-query(( > cts:directory-query("/metadata/", "1"), > cts:element-value-query(xs:QName("ns:status"), "New", > "exact"), > cts:element-value-query(xs:QName("ns:user"), "Ed", "exact"), > cts:element-value-query(xs:QName("ns:doc-id"), > "1234", "exact") > )) > > end plugging the $query variable into your example: > > search:resolve-nodes( > document { $query }/*, $options, $page-start, $page-size) ? > > Also, is there a way to feed the resulting XML of a query into the > search:resolve-nodes function? I end up having to join my results with > another document to obtain all of the desired columns. > > Thanks again, Tim > > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Michael > Blakeley > Sent: Wednesday, March 27, 2013 6:07 PM > To: MarkLogic Developer Discussion > Subject: Re: [MarkLogic Dev General] How to program the order by clause in > FLWOR? > > If you already have code to generate a cts:query and format results, you > might prefer search:resolve-nodes. That way you won't have to change as much > code, but it will still replace your FLWOR expression to handle sorting and > pagination. You'll just have to construct a search:options node for the > sorting, and provide the pagination and cts:query. The query has to be XML, > which you can generate using easily. > > search:resolve-nodes( > document { $query }/*, $options, $page-start, $page-size) > > http://docs.marklogic.com/search:resolve-nodes has more, and > http://docs.marklogic.com/search:search outlines the search options. Look > for '<sort-order>', like this example: > > <sort-order type="xs:string" > collation="http://marklogic.com/collation/" > direction="ascending"> > <element ns="my-namespace" name="my-element"/> > <annotation>some user comment can go here</annotation> </sort-order> > <sort-order direction="ascending"> > <score/> > </sort-order> > > -- Mike > > On 27 Mar 2013, at 14:12 , "Tim" <[email protected]> wrote: > >> Hi Mike, >> >> True, plus I need to implement pagination. It seems like the >> search:search functionality is ideal, but I have a little bit of a > learning curve with it. >> I have looked at the documentation, but I'm wondering if there are any >> examples available of transforming a cts:search into a search:search >> function call? >> >> Thanks again, >> >> Tim >> >> -----Original Message----- >> From: [email protected] >> [mailto:[email protected]] On Behalf Of Michael >> Blakeley >> Sent: Wednesday, March 27, 2013 5:04 PM >> To: MarkLogic Developer Discussion >> Subject: Re: [MarkLogic Dev General] How to program the order by >> clause in FLWOR? >> >> What I mean is that if you want to support N sort keys, each ascending >> or descending, you'll need to enumerate 2N conditionals. With string >> concatenation and xdmp:value you can support any number, with much >> less code. And then if you want to support multiple dynamic sort keys >> at the same time, things get ugly fast. >> >> -- Mike >> >> >> >> _______________________________________________ >> General mailing list >> [email protected] >> http://developer.marklogic.com/mailman/listinfo/general >> > > _______________________________________________ > General mailing list > [email protected] > http://developer.marklogic.com/mailman/listinfo/general > > _______________________________________________ > General mailing list > [email protected] > http://developer.marklogic.com/mailman/listinfo/general > _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
