It looks like appfunctions.xqy has gone away in ML6.0 and I assume this is why:

The applications generated from Application Builder are considerably different 
in MarkLogic 6 than they were in MarkLogic 5. In MarkLogic 6, the applications 
use the REST API and do not have any XQuery code. The following are some of the 
differences:
*The generated applications use the REST API and are hosted on a REST API 
instance.
*The generated applications are now 100% html and javascript; there is no 
XQuery code directly in the application.
*Any customizations built in MarkLogic 5 will be lost if you re-generate the 
application in MarkLogic 6.

If you have customizations of your generated applications or if you rely on any 
of the old application features, then you will need to rework those in 
MarkLogic 6. For details on Application Builder and the applications it 
generates, see the...

However, when I look at the documentation, it really doesn't give me any direct 
examples on how to do custom snippets...

So, in short, I want to do a custom snippet and in the past, I simply created 
the snippet module and referenced it in the appfunctions.xqy file.  With the 
appfunctions.xqy file not being in the /custom/ directory, I'm getting an error 
trying to accomplish this in 6.0 according to what I think the equivalent is.

It seems to me that perhaps, under the "Search" tab in App Builder, there is a 
"Custom XML Options" button.
So, I added my option there:
  <transform-results apply="adv-snippet" ns="/custom/snippet" 
at="/custom/dsnip.xqy">
     <per-match-tokens>40</per-match-tokens>
     <max-matches>5</max-matches>
     <max-snippet-chars>200</max-snippet-chars>
  </transform-results>


I put this module in the /custom directory:
module namespace dsnip = "/custom/snippet";

import module namespace search = "http://marklogic.com/appservices/search";
    at "/MarkLogic/appservices/search/search.xqy";


declare function dsnip:adv-snippet(
         $result as node(),
         $ctsquery as schema-element(cts:query),
         $options as element(search:transform-results)?
) as element(search:snippet)
{
<search:snippet>
{
for $match in search:snippet($result, $ctsquery, $options)/search:match
return
<search:match>
{
if (fn:data($ctsquery/@qtextempty) = "1") then () else
(
   
<i>{fn:concat(fn:string(fn:node-name(xdmp:eval(xs:string(fn:data($match/@path))))),
 ":&nbsp;")}</i>,
   $match/node(),<br/>
)
}
</search:match>
}
</search:snippet>
};


I gave it the following persmissions:
xdmp:document-load("/home/tpf106/davids/xquery/snippet/dsnip.xqy",
    <options xmlns="xdmp:document-load">
      <uri>/application/custom/dsnip.xqy</uri>
      <repair>none</repair>
      <permissions>{(xdmp:permission("app-user", "execute"),
     xdmp:permission("app-user", "read"),
     xdmp:permission("app-builder", "update"))}</permissions>
    </options>)


I try to deploy and I get a server error...
2013-02-11 16:14:06.451 Info: AdvantageSearch:   
<error:code>XDMP-AS</error:code>
2013-02-11 16:14:06.451 Info: AdvantageSearch:   
<error:name>err:XPTY0004</error:name>
2013-02-11 16:14:06.451 Info: AdvantageSearch:   
<error:xquery-version>1.0-ml</error:xquery-version>
2013-02-11 16:14:06.451 Info: AdvantageSearch:   <error:message>Invalid 
coercion</error:message>
2013-02-11 16:14:06.451 Info: AdvantageSearch:   <error:format-string>XDMP-AS: 
(err:XPTY0004) $test-elem as element() -- Invalid coercion: (&lt;transform-res
ults apply="empty-snippet" 
xmlns="http://marklogic.com/appservices/search"/&gt;, &lt;transform-results 
apply="adv-snippet" ns="/custom/snippet" at="/custom/d
snip.xqy" 
xmlns="http://marklogic.com/appservices/search"&gt;&lt;per-match-tokens&gt;40&lt;/per-match-tokens&gt;&lt;max-matches&gt;5&lt;/max-match...&lt;/tra
nsform-results&gt;) as element()</error:format-string>
2013-02-11 16:14:06.451 Info: AdvantageSearch:   
<error:retryable>false</error:retryable>
2013-02-11 16:14:06.451 Info: AdvantageSearch:   <error:expr>$test-elem as 
element()</error:expr>
2013-02-11 16:14:06.451 Info: AdvantageSearch:   <error:data>
2013-02-11 16:14:06.451 Info: AdvantageSearch:     
<error:datum>(&lt;transform-results apply="empty-snippet" 
xmlns="http://marklogic.com/appservices/search"/
&gt;, &lt;transform-results apply="adv-snippet" ns="/custom/snippet" 
at="/custom/dsnip.xqy" 
xmlns="http://marklogic.com/appservices/search"&gt;&lt;per-match-
tokens&gt;40&lt;/per-match-tokens&gt;&lt;max-matches&gt;5&lt;/max-match...&lt;/transform-results&gt;)</error:datum>
2013-02-11 16:14:06.451 Info: AdvantageSearch:     
<error:datum>element()</error:datum>
2013-02-11 16:14:06.451 Info: AdvantageSearch:   </error:data>
2013-02-11 16:14:06.451 Info: AdvantageSearch:   <error:stack>
2013-02-11 16:14:06.451 Info: AdvantageSearch:     <error:frame>
2013-02-11 16:14:06.451 Info: AdvantageSearch:       
<error:uri>/MarkLogic/appservices/search/search-impl.xqy</error:uri>
2013-02-11 16:14:06.451 Info: AdvantageSearch:       
<error:line>2842</error:line>
2013-02-11 16:14:06.451 Info: AdvantageSearch:       
<error:column>27</error:column>
2013-02-11 16:14:06.451 Info: AdvantageSearch:       
<error:operation>impl:snippet-dispatch(&lt;options 
xmlns="http://marklogic.com/appservices/search"&gt;&l
t;return-facets&gt;true&lt;/return-facets&gt;&lt;return-results&gt;true&lt;/return-...&lt;/options&gt;,
 &lt;cts:and-query xmlns:cts="http://marklogic.com/cts
"/&gt;, &lt;cts:and-query xmlns:cts="http://marklogic.com/cts"/&gt;, 
fn:doc("/trdmks/6284137186018113427.xml"))</error:operation>
2013-02-11 16:14:06.451 Info: AdvantageSearch:       <error:variables>
2013-02-11 16:14:06.451 Info: AdvantageSearch:  <error:variable>
2013-02-11 16:14:06.451 Info: AdvantageSearch:    <error:name 
xmlns="http://marklogic.com/appservices/search-impl";>options</error:name>
2013-02-11 16:14:06.451 Info: AdvantageSearch:    <error:value>&lt;options 
xmlns="http://marklogic.com/appservices/search"&gt;&lt;return-facets&gt;true&lt;/r
eturn-facets&gt;&lt;return-results&gt;true&lt;/return-...&lt;/options&gt;</error:value>
2013-02-11 16:14:06.451 Info: AdvantageSearch:  </error:variable>
....

So, I'm at the end of what I can get out of the 6.0 documentation...  Though 
it's very possible that I'm missing something...



Thanks,
David

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

Reply via email to