No worries, it's a completely reasonable thing to want to do...

Sent from my iPhone

On Aug 10, 2011, at 1:50 PM, "Mattio Valentino" <[email protected]> 
wrote:

> Thanks, both! Sorry to bother you with such an odd edge case. I
> thought I was making it easier by just defining it in the same module
> while testing.
> 
> On Wed, Aug 10, 2011 at 4:32 PM, Colleen Whitney
> <[email protected]> wrote:
>> You do need a library module to use extensions in the search API.
>> 
>> ________________________________________
>> From: [email protected] 
>> [[email protected]] On Behalf Of Michael Blakeley 
>> [[email protected]]
>> Sent: Wednesday, August 10, 2011 1:33 PM
>> To: General MarkLogic Developer Discussion
>> Subject: Re: [MarkLogic Dev General] Calling a custom function using    
>> search:search in cq
>> 
>> I still don't know the search API as well as I might. But I believe that the 
>> first problem is that functions are described by a local-name and a 
>> namespace. You've only supplied the local-name "custom-snippet" and not the 
>> namespace "http://www.w3.org/2005/xquery-local-functions";. I wasn't sure how 
>> to do this, so I checked 
>> http://developer.marklogic.com/pubs/4.2/books/search-dev-guide.pdf and found 
>> an example in 2.1.7 "Search Customization Via Options and Extensions".
>> 
>>  <options xmlns="http://marklogic.com/appservices/search";>
>>    <transform-results apply="custom-snippet"
>>     ns="http://www.w3.org/2005/xquery-local-functions"/>
>>  </options>
>> 
>> This throws a new error:
>> 
>>  SEARCH-BADEXTENSION: (err:FOER0000) Extensions must define @apply, @ns and 
>> @at
>> 
>> We're making progress, but @at seems to be the library module location (eg, 
>> '/lib.xqy'). So it looks like you have to put the function into a library 
>> module. The function can't be defined in the cq textarea, because that area 
>> needs to define a main module. Even if cq could define a library module, it 
>> wouldn't have a location for transform-results to refer to.
>> 
>> -- Mike
>> 
>> On 10 Aug 2011, at 10:05 , Mattio Valentino wrote:
>> 
>>> I was trying to test adding my own search snippeting function using
>>> the search:search API but ran into some trouble trying to use it in
>>> cq. I was trying to keep the custom function in the same main module
>>> as the search itself. I keep getting the error:
>>> 
>>> [1.0-ml] SEARCH-APPLYUNDEFINED: (err:FOER0000) Value of @apply
>>> undefined: custom-snippet
>>> 
>>> Is there a trick to make this work in the same module in cq or does
>>> the custom function have to be in a separate file with @ns and @at
>>> defined?
>>> 
>>> The query is below.
>>> 
>>> Thanks!
>>> 
>>> xquery version "1.0-ml";
>>> import module namespace
>>> search="http://marklogic.com/appservices/search"; at
>>> "/MarkLogic/appservices/search/search.xqy";
>>> 
>>> declare function local:custom-snippet(
>>>  $result as node(),
>>>  $ctsquery as schema-element(cts:query),
>>>  $options as element(search:transform-results)?
>>> ) as element(search:snippet)
>>> {
>>>  (:search:snippet($result, $ctsquery, $options):)
>>>  <search:snippet/>
>>> };
>>> 
>>> search:search("blue",
>>>  <options xmlns="http://marklogic.com/appservices/search";>
>>>    (: I've tried multiple variations of this node :)
>>>    <transform-results apply="custom-snippet"/>
>>>  </options>
>>> )
>>> _______________________________________________
>>> 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
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to