Hi Spike-
I think the issue here is that '/mydocument' is never being evaluated as xpath.

You might want to try xdmp:eval.

You may have to refactor things a little, but a pattern that applies is:

let $e-string := fn:concat("let $q := 'the' ", "return cts:search( "/ mydocument,'", "$q)")
return xdmp:eval($e-string)

You could create a method to return the query constructor code (the "let $q := 'the' " part) as a string. This assumes /mydocument does indeed evaluate properly. The trick is in providing all the info needed in the eval context (variables, namespaces mostly.)

If your code becomes too complex to manage with an eval string, you could look into xdmp:invoke, which might allow you to create something that's more sophisticated and maintainable.

Frank


On Aug 18, 2009, at 10:34 AM, Grobstein, Spike wrote:

Thanks Geert,

I'm trying to pass the xpath as a string, so I call like this:

cleanup:find($thirty_days, '/mydocument')

and in the function, I have:

cts:search(xdmp:value($base_context), $query)

I'm still getting the error about being unsearchable.

I don't understand what you mean about using concat() to make it a
complete expression, though. I assume you meant to put the leading / on
it?


...spike

-----Original Message-----
From: general-boun...@developer.marklogic.com
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Geert
Josten
Sent: Tuesday, August 18, 2009 10:25 AM
To: General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] using function parameter as
contextforcts:search

Hi Spike,

I see two options:
- replace your xpath with some query which can be passed as parameter
and added to the and-query
- pass the xpath as a string, use concat to make it a complete
expression and use xdmp:value to execute the string expression

Kind regards,
Geert




Drs. G.P.H. Josten
Consultant


http://www.daidalos.nl/
Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665 JZ Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
http://www.daidalos.nl/
KvK 27164984
De informatie - verzonden in of met dit emailbericht - is afkomstig van
Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u
dit bericht onbedoeld hebt ontvangen, verzoeken wij u het te
verwijderen. Aan dit bericht kunnen geen rechten worden ontleend.


From: general-boun...@developer.marklogic.com
[mailto:general-boun...@developer.marklogic.com] On Behalf Of
Grobstein, Spike
Sent: dinsdag 18 augustus 2009 16:15
To: general@developer.marklogic.com
Subject: [MarkLogic Dev General] using function parameter as
context for cts:search

Hi,



I'm writing a cleanup function that takes a base context to
match to find documents that should be deleted:



(: returns a sequence of URIs that should be deleted in the
context of $base_context (ie: /ra_document) that's older than
$duration :)

declare function cleanup:find($duration as
xs:dayTimeDuration, $base_context as node()*)

{

 let $query :=

   cts:and-query((

     cts:element-range-query(xs:QName('started_at'), '<=',
fn:current-dateTime() - $duration)

   ))

 for $doc in cts:search($base_context, $query)

 return (xdmp:node-uri($doc))

};



cleanup:find(xs:dayTimeDuration('P60D'), /some_document)



------------------8< snip --------------------------------------



When I run that, I get an error that the expression is unsearchable.



What I'd like to do is provide a base context to do the
search on (ie: a document node type).



Is there any way to do this?





.spike



_______________________________________________
General mailing list
General@developer.marklogic.com
http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
General@developer.marklogic.com
http://xqzone.com/mailman/listinfo/general

_______________________________________________
General mailing list
General@developer.marklogic.com
http://xqzone.com/mailman/listinfo/general

Reply via email to