Ah, I was going down the wrong with <cts:annotation>. The
cts:field-word-query() doesn't seem to provide a way to supply the annotation,
but using serialized cts:query XML worked:
declare function no:search-term(
$ps as map:map,
$term as element()?)
as schema-element(cts:query)
{
let $tok := sdev:current($ps)/string()
return
<cts:field-word-query qtextconst="{ $tok }">
<cts:field>my-field</cts:field>
<cts:text>{ $tok }</cts:text>
{ $term/search:term-option[
not(starts-with(., "lang="))]/element cts:option { string() } }
</cts:field-word-query>
,
sdev:advance($ps)
};
Thanks Dave!
-Will
> On Jan 28, 2015, at 2:53 PM, Dave Cassel <[email protected]> wrote:
>
> Take a look at the example here. You can add a qtextconst attribute that
> reflects the original query.
>
> I did a blog post about this a few years ago. May be dated (it predates
> structured queries), but I think the essentials are still accurate.
>
> --
> Dave Cassel
> Developer Community Manager
> MarkLogic Corporation
>
>
> From: Will Thompson <[email protected]>
> Reply-To: MarkLogic Developer Discussion <[email protected]>
> Date: Wednesday, January 28, 2015 at 3:47 PM
> To: MarkLogic Developer Discussion <[email protected]>
> Subject: [MarkLogic Dev General] Search API: Can't unparse after <term>
> extension?
>
>> (Using ML 7.0-4.1) I added an extension to my Search API options to
>> transform terms into field-word-queries:
>>
>> declare function my:search-term(
>> $ps as map:map,
>> $term as element()?)
>> as schema-element(cts:query)
>> {
>> document {
>> cts:field-word-query(
>> 'my-field',
>> sdev:current($ps),
>> $term/search:term-option[
>> not(starts-with(., "lang="))]/element cts:option { string() }) }/*
>> ,
>> sdev:advance($ps)
>> };
>>
>> Parsing works exactly as expected, however unparse() throws an exception:
>> "SEARCH-NONANNOTATED: (err:FOER0000) Non-annotated query"
>>
>> let $parsed :=
>> search:parse("test",
>> <options xmlns="http://marklogic.com/appservices/search">
>> <term apply="search-term" ns="http://myns" at="/mymodule.xqm">
>> <empty apply="no-results" />
>> </term>
>> </options>)
>> return search:unparse($parsed)
>>
>> I poked around search-impl.xqy and tried to create my own <cts:annotation>,
>> but I have not been successful. I suspect there is some nuance I'm missing.
>> Any suggestions? Is this possible? It seems like it should be.
>>
>> Thanks,
>>
>> Will
>> _______________________________________________
>> 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