[MarkLogic Dev General] cts.search v cts:search

Michael Blakeley mike at blakeley.com
Tue Mar 3 19:11:58 PST 2015


But won't that also return word elements that don't match, from documents that match? I think you'd have to check every element with cts.contains and the original query.

Did you notice there's a fragment root on the word element? I think that will also cause problems, because the parent document won't match the query.

The sorting is indeed ugly: in the original it won't be efficient because the ../@year accesses the parent fragment. Even if there's a range index, I don't think sorting can use it there.

-- Mike

> On 3 Mar 2015, at 15:35 , Danny Sokolsky <Danny.Sokolsky at marklogic.com> wrote:
> 
> You can xpath down the results in JavaScript.  In your case, you end up returning the whole document anyway I think because you are walking up the tree from //word.
> 
> This is not quite what you want to do, but it is similar (and requires a range index on concepts/@year)
> 
> var res = new Array();
> for (var x of cts.search(cts.elementWordQuery(xs.QName("word"), 
>                                  "tenant for life", ["exact"]),
>                        cts.indexOrder(
>                          cts.elementAttributeReference(
>                            xs.QName("concepts"), xs.QName("year"))))) {
> res.push(x.xpath(".//word"));
> };
> res;
> 
> -Danny
> 
> -----Original Message-----
> From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Michael Blakeley
> Sent: Tuesday, March 03, 2015 12:46 PM
> To: MarkLogic Developer Discussion
> Subject: Re: [MarkLogic Dev General] cts.search v cts:search
> 
> Just guessing, but it might be pretty difficult to allow searchable expression arguments within a JavaScript evaluation environment. It might mean extending JavaScript syntax, or passing in the searchable expression as a string.
> 
> Speaking of strings, one workaround would be to do that bit in XQuery and call the XQuery from JavaScript. You could pass in a string that holds the searchable expression, and use that to build a cts:search expression, then call xdmp:value.
> 
> But if that sounds familiar, maybe it's because that's pretty much what search:resolve-nodes already does. You should be able to require() the search API module into your server-side JavaScript code and call it from there.
> 
> -- Mike
> 
>> On 3 Mar 2015, at 11:56 , Steiner, David J. (LNG-DAY) <David.J.Steiner at elsevier.com> wrote:
>> 
>> I’m trying to implement a search in javascript.  In xquery, with cts:search you can specify an element to be searched and returned, such as: cts:search(//element.
>> 
>> The javascript cts.search doesn’t seem to have this ability.  Is there a way to affect this in javascript?  I really don’t want the whole doc coming back, just the element.  Yes, the element is a fragment.
>> 
>> Here’s the XQuery I’m trying to replicate in javascript:
>> 
>> for $hit in  cts:search(//word,
>>    cts:element-word-query(
>>      xs:QName("word"),
>>      "tenant for life",
>>      "exact"))
>> order by fn:data($hit/../@year)
>> return
>> 
>> XML documents looks like this:
>> <concepts year="1865">
>> <word count="8">tenant for life</word> <word count="5">decree of 
>> court</word> <word count="4">fourth part</word> … </concepts>
>> 
>> 
>> Thanks,
>> David
>> 
>> 
>> _______________________________________________
>> General mailing list
>> General at developer.marklogic.com
>> http://developer.marklogic.com/mailman/listinfo/general
> 
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general



More information about the General mailing list