Geert - 

Not a question, but thank you for the suggestion. I do have another somewhat 
related question about using the extension hook for snippets...  

I was able to get a "hello world" extension module working, but only after a 
very confusing error regarding the snippet namespace and a workaround.  But I 
could be misunderstanding something.  

My snippet module essentially looks like this:

module namespace s = "http://xyz.com/s";;
...
declare function s:do-snippet(
    $result as node(),
    $ctsquery as schema-element(cts:query),
    $options as element(search:transform-results)?
) as element(search:snippet)
{
    let $r := "hello world"
    return <search:snippet><search:match>{$r}</search:match></search:snippet>
};

And I hooked into using the snippet extension in <options> using:

<transform-results apply="do-snippet" ns="s" at="/my-snippet.xqm"/>

However, this results in an error:

500 Internal Server Error
XDMP-IMPMODNS: (err:XQST0059) Import module namespace s does not match target 
namespace http://xyz.com/s of imported module /my-snippet.xqm
in xdmp:function(fn:QName("s", "do-snippet"), "/my-snippet.xqm") [1.0-ml]
...

What eventually worked was changing my module namespace declaration to:

module namespace s = "s";

I did some more testing, and as far as I can tell it insists that the namespace 
prefix and URI match exactly. I couldn't find anything about this in the Search 
API documentation - Is there a reason it won't let me declare using a full URI? 

Thanks,

Will


-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Geert Josten
Sent: Monday, February 28, 2011 1:10 PM
To: General MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Special elements in Snippets

Hi Will,

It that a question? Just wanted to mention that instead of copying all 
libraries, you could perhaps reference the original ones partly..

Kind regards,
Geert

-----Oorspronkelijk bericht-----
Van: [email protected] 
[mailto:[email protected]] Namens Will Thompson
Verzonden: maandag 28 februari 2011 17:27
Aan: General MarkLogic Developer Discussion
Onderwerp: Re: [MarkLogic Dev General] Special elements in Snippets

Okay, thanks Danny.

I had started on my own function using the extension hooks provided by the API, 
but stopped short once I realized there were several other XQY scripts used by 
ML's implementation that would also have to be copied.  I thought I would ping 
you guys just in case there were an easier solution.  Thanks for the feedback.

Best regards,

Will


-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Danny Sokolsky
Sent: Friday, February 25, 2011 7:23 PM
To: General MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Special elements in Snippets

BTW, the Search API chapter in the Search Developer's Guide describes the 
extension mechanism here:

http://docs.marklogic.com/4.2doc/docapp.xqy#display.xqy?fname=http://pubs/4.2doc/xml/search-dev-guide/search-api.xml%2328383

-Danny

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Danny Sokolsky
Sent: Friday, February 25, 2011 5:15 PM
To: General MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Special elements in Snippets

Hi Will,

I would not modify the source directly.  Instead, you can use the search API's 
extension mechanism to create your own function, stored in your own environment 
(ie, in your App Server root), and use the apply attribute of 
search:transform-results.  Then you can start by copying the code from the 
search API, if you wish.   The reason you should not modify the search API code 
directly is that it will get overridden upon upgrade of MarkLogic Server.

For example, if you have a library called my-library.xqy in your App Server 
root, you can add this option to your search:options node:


<transform-results apply="snippet" ns="my-namespace"
                   at="/my-library.xqy"/>

Then it will use the snippet function from your library instead of the built-in 
one.

-Danny

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Will Thompson
Sent: Friday, February 25, 2011 4:05 PM
To: [email protected]
Subject: [MarkLogic Dev General] Special elements in Snippets

Hello all,

Search:snippet does almost everything I need, and in lieu of starting from 
scratch with another snippet library for one feature, I'm considering modifying 
the source of snippet.xqy.

I need certain elements to be passed through to the snippet without being 
converted to text so they can be styled correctly when the snippet is 
transformed into HTML.  I also want to ignore these elements when highlighting.

Other than this the API is ideal, and it seems like a waste to start from 
scratch for just one feature.  Does anyone have any comments about modifying 
the Search API source?  Or if there is possibly a 3rd way to go about this that 
I'm not considering?  

Thanks,

Will Thompson
Jones McClure Publishing
713.335.8247
_______________________________________________
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
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to