[MarkLogic Dev General] Aggregate functions in search:search

Geert Josten Geert.Josten at marklogic.com
Mon Jul 20 06:35:41 PDT 2015


Hi,

If you are calling search:values manually anyhow, you could embed your cts:query inside the search options as search:additional-query. Then you don’t need the 3rd param.

<search:additional-query>{$myctsquery}</search:additional-query>

Note: this works only in XQuery context, not with stored options like with REST-api..

Cheers,
Geert

From: <general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com>> on behalf of Basavaraj Kalloli <basavarajkalloli at gmail.com<mailto:basavarajkalloli at gmail.com>>
Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Date: Monday, July 20, 2015 at 1:52 PM
To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
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 <Geert.Josten at marklogic.com<mailto:Geert.Josten at marklogic.com>> 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: <general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com>> on behalf of Basavaraj Kalloli <basavarajkalloli at gmail.com<mailto:basavarajkalloli at gmail.com>>
Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Date: Monday, July 20, 2015 at 10:57 AM
To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
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
General at developer.marklogic.com<mailto:General at developer.marklogic.com>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20150720/d6f91ddd/attachment-0001.html 


More information about the General mailing list