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]<mailto:[email protected]>>
 on behalf of Basavaraj Kalloli 
<[email protected]<mailto:[email protected]>>
Reply-To: MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Date: Monday, July 20, 2015 at 10:57 AM
To: MarkLogic Developer Discussion 
<[email protected]<mailto:[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

Reply via email to