Hi Rajamani,

I dint use the above one in our case we just created constraints using
range indexes and sorted them by ascending and descending and apply a limit
of 1.

We dint go more into search:values because we wanted it work with
cts:queries but as Geert pointed out we need to pass that as an additional
query in options.

On Tue, Jul 21, 2015 at 4:26 PM, <[email protected]> wrote:

>  Hi Basavaraj,
>
>
>
> Did you try something like following , I have formed structured query as
> third param  for the given scenario.
>
>
>
>
>
> import module namespace search = "http://marklogic.com/appservices/search";
> at "/MarkLogic/appservices/search/search.xqy";
>
> let $searchQ := <search:query xmlns:search="
> http://marklogic.com/appservices/search";>
>
>   <search:and-query>
>
>     <search:term-query>
>
>       <search:text>abc</search:text>
>
>     </search:term-query>
>
>     <search:collection-query>
>
>       <search:uri>test1</search:uri>
>
>     </search:collection-query>
>
>   </search:and-query>
>
> </search:query>
>
>
>
> let  $options :=
>
>     <options xmlns="http://marklogic.com/appservices/search";>
>
>         <values name="example">
>
>           <range type="xs:int">
>
>             <element ns="" name="size"/>
>
>           </range>
>
>         <aggregate apply="max"/>
>
>         </values>
>
>         <search:additional-query>{$searchQ}</search:additional-query>
>
>     </options>
>
>
>
>
>
>
>
> return search:values("example", $options,$searchQ)
>
>
>
> Thanks and regards
>
> Raja >>>
>
>
>
> *From:* [email protected] [mailto:
> [email protected]] *On Behalf Of *Basavaraj Kalloli
> *Sent:* Monday, July 20, 2015 5:23 PM
> *To:* MarkLogic Developer Discussion
> *Subject:* Re: [MarkLogic Dev General] Aggregate functions in
> search:search
>
>
>
> Hi Geert,
>
>
>
> Thanks for the response so we are back to using search:values.
>
>
>
> For eg:
>
>
>
> cts:and-query((cts:word-query("some word"), cts:collection-query("some
> collection")))
>
>
>
> search:values takes third parameter as a structured query i.e search:query
>
>
>
> https://docs.marklogic.com/search:parse
>
>
>
> But we have a cts:and-query so we are not sure how to convert this to a
> structured query. We have tried search:parse but it doesnt work.
>
>
>
> On Mon, Jul 20, 2015 at 2:40 PM, Geert Josten <[email protected]>
> wrote:
>
> Hi Basavaraj,
>
>
>
> I’m afraid the documentation is a bit misleading. Your observation is
> correct, search:search ignores settings like values and tuples, they are
> only interpreted by search:values. Similarly suggestion sources are only
> interpreted by search:suggest. This makes it easier to have all search
> related options in one file, and share them among multiple functions.
> Particularly useful in REST api..
>
>
>
> Cheers,
>
> Geert
>
>
>
> *From: *<[email protected]> on behalf of Basavaraj
> Kalloli <[email protected]>
> *Reply-To: *MarkLogic Developer Discussion <
> [email protected]>
> *Date: *Monday, July 20, 2015 at 10:57 AM
> *To: *MarkLogic Developer Discussion <[email protected]>
> *Subject: *[MarkLogic Dev General] Aggregate functions in search:search
>
>
>
> We need to calculate max values of two nodes for a given search query.
> From MarkLogic documentation we could see that we could achieve this using
> values in the options node of search:search. Example below:
>
>
>
> We have 2 documents:
>
>
>
> <document>
>
>         <name>abc</name>
>
>         <size>12</size></document><document>
>
>         <name>abc</name>
>
>         <size>4</size></document>
>
>
>
>  We tried to find the max/min using search:search as below:
>
>
>
> *xquery* *version* "1.0-ml";
>
> *declare* *namespace* *html* = "http://www.w3.org/1999/xhtml";;
>
>
>
> *import* *module* *namespace* *search* = 
> "http://marklogic.com/appservices/search"; *at* 
> "/MarkLogic/appservices/search/search.xqy";
>
>
>
> *declare* *variable* $options :=
>
>     <options xmlns="http://marklogic.com/appservices/search";>
>
>         <values name="example">
>
>           <range type="xs:int">
>
>             <element ns="" name="size"/>
>
>           </range>
>
>         <aggregate apply="max"/>
>
>         </values>
>
>     </options>;
>
>
>
> *search:search*("abc", $options)
>
>
>
> this does not return values-response node which this documentation claims:
> http://docs.marklogic.com/search:search#opt-values
>
>
>
> If we use search:values as below then it returns values-response:
>
>
>
> *xquery* *version* "1.0-ml";
>
> *declare* *namespace* *html* = "http://www.w3.org/1999/xhtml";;
>
>
>
> *import* *module* *namespace* *search* = 
> "http://marklogic.com/appservices/search"; *at* 
> "/MarkLogic/appservices/search/search.xqy";
>
>
>
> *declare* *variable* $options :=
>
>     <options xmlns="http://marklogic.com/appservices/search";>
>
>         <values name="example">
>
>           <range type="xs:int">
>
>             <element ns="" name="size"/>
>
>           </range>
>
>         <aggregate apply="max"/>
>
>         </values>
>
>     </options>;
>
> *search:values*("example", $options)
>
>
>
> Output:
>
>
>
> <search:values-response name="example" type="xs:int" 
> xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
> xmlns:search="http://marklogic.com/appservices/search";>
>
>           <search:distinct-value frequency="1">4</search:distinct-value>
>
>           <search:distinct-value frequency="1">12</search:distinct-value>
>
>           <search:aggregate-result name="max">12</search:aggregate-result>
>
>           <metrics xmlns="http://marklogic.com/appservices/search";>
>
>             <values-resolution-time>PT0.001927S</values-resolution-time>
>
>             <aggregate-resolution-time>PT0.00242S</aggregate-resolution-time>
>
>             <total-time>PT0.005973S</total-time>
>
>           </metrics>
>
>  </search:values-response>
>
>
>
>
>
> Theoretically this should work with search:search as well but somehow it
> completely ignores values node. Are we missing something obvious here or
> some other config is needed?
>
>
> _______________________________________________
> General mailing list
> [email protected]
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>
>  This e-mail and any files transmitted with it are for the sole use of
> the intended recipient(s) and may contain confidential and privileged
> information. If you are not the intended recipient(s), please reply to the
> sender and destroy all copies of the original message. Any unauthorized
> review, use, disclosure, dissemination, forwarding, printing or copying of
> this email, and/or any action taken in reliance on the contents of this
> e-mail is strictly prohibited and may be unlawful. Where permitted by
> applicable law, this e-mail and other e-mail communications sent to and
> from Cognizant e-mail addresses may be monitored.
>
> _______________________________________________
> General mailing list
> [email protected]
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to