I want to run the following query using MarkLogic's Java Client API but can't seem to find the correct way. The query is as follows :
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
declare variable $searchQuery as xs:string external ;
declare variable $aggregateFunc as xs:string external ;
let $searchQuery := 'ticker:CSGN.VX AND (dateRange GE "2015-08-07" AND dateRange LE "2015-08-21")'
let $query :=
search:parse( $searchQuery,
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="dateRange">
<range type="xs:date" facet="false">
<element ns="" name="date"/>
</range>
</constraint>
<constraint name="ticker">
<range type="xs:string" >
<element ns="" name="ticker"/>
</range>
</constraint>
</options>,
"search:query"
)
let $r :=
search:values(
'closingPrice',
<options xmlns="http://marklogic.com/appservices/search">
<values name="closingPrice">
<range type="xs:double">
<element ns="" name="closingPrice"/>
</range>
<aggregate apply="avg"/>
</values>
</options>,
$query
)
return <result>{$r}</result>
I have implemented the following query using MarkLogic XCC but need to know how to implement the same using Client API.
As per discussion i formed the following query however it still doesn't return any results, let me know if something is wrong.
QueryManager queryMgr = client.newQueryManager();
ServerConfigurationManager configManager = client.newServerConfigManager();
configManager.newNamespacesManager();
QueryOptionsManager optionsMgr = configManager.newQueryOptionsManager();
optionsMgr.writeOptions(VALUE_OPTION, new StringHandle(VALUE_OPTIONS));
StringQueryDefinition qd = queryMgr.newStringDefinition(VALUE_OPTION);
qd.setCriteria("ticker:CSGN.VX AND (dateRange GE \"2015-08-07\" AND dateRange LE \"2015-08-21\")");
ValuesDefinition vdef =
queryMgr.newValuesDefinition("closingPrice", VALUE_OPTION);
vdef.setQueryDefinition(qd);
vdef.setAggregate("avg");
ValuesHandle results = queryMgr.values(vdef, new ValuesHandle());
StringHandle strResults=queryMgr.values(vdef, new StringHandle());
Where the value options are :
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="dateRange">
<range type="xs:date" facet="false">
<element ns="" name="date"/>
</range>
</constraint>
<constraint name="ticker">
<range type="xs:string" >
<element ns="" name="ticker"/>
</range>
</constraint>
<values name="closingPrice">
<range type="xs:double">
<element ns="" name="closingPrice"/>
</range>
</values>
</options>