I want to sort results on the basis of facet count. How can I go that in search:search?
As of now, I am using this query -
let $options :=
<options xmlns="http://marklogic.com/appservices/search">
<return-metrics>false</return-metrics>
<return-facets>true</return-facets>
<return-results>false</return-results>
<additional-query>{cts:query($cts-query)}</additional-query>
<constraint name="decade">
<range type="xs:dateTime" facet="true">
<bucket lt="2002-01-01T00:00:00Z" ge="2001-01-01T00:00:00Z" name="2001">2001</bucket>
<bucket lt="2003-01-01T00:00:00Z" ge="2002-01-01T00:00:00Z" name="2002">2002</bucket>
<bucket lt="2004-01-01T00:00:00Z" ge="2003-01-01T00:00:00Z" name="2003">2003</bucket>
<bucket ge="2004-01-01T00:00:00Z" name="2004">2004</bucket>
<facet-option>limit=10</facet-option>
<element ns="http://iddn.icis.com/ns/core" name="released-on"/>
</range>
</constraint>
<operator>
<state>
<sort-order direction="descending" type="xs:integer">
<score/>
</sort-order>
</state>
</operator>
</options>
let $date-seq := search:search("*", $options)
return $date-seq
I want to change the options so that I can sort the facet results by facet count.
Haven't tried this with buckets, but normally I think you'd add facet-options "frequency-order" and "descending":
<constraint name="decade">
<range type="xs:dateTime" facet="true">
<bucket lt="2002-01-01T00:00:00Z" ge="2001-01-01T00:00:00Z" name="2001">2001</bucket>
<bucket lt="2003-01-01T00:00:00Z" ge="2002-01-01T00:00:00Z" name="2002">2002</bucket>
<bucket lt="2004-01-01T00:00:00Z" ge="2003-01-01T00:00:00Z" name="2003">2003</bucket>
<bucket ge="2004-01-01T00:00:00Z" name="2004">2004</bucket>
<facet-option>limit=10</facet-option>
<facet-option>frequency-order</facet-option>
<facet-option>descending</facet-option>
<element ns="http://iddn.icis.com/ns/core" name="released-on"/>
</range>
</constraint>
Related
I would like to turn this xml response into something more easily readable.
<?xml version="1.0" encoding="ISO-8859-1"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
<soap:Body>
<executeResponse xmlns="urn:GCE">
<BusinessViewServiceexecuteOut xmlns="http://www.generix.fr/technicalframework/businesscomponent/applicationmodule/common" xmlns:ns2="http://www.generixgroup.com/processus/configuration/scheduler" xmlns:ns3="http://www.generix.fr/technicalframework/business/service/common">
<xmlpres><?xml version = '1.0' encoding = 'UTF-8'?> <VueTable type="View" name="Table" habctr="true" total_business_row="2" nbline="400" confNbline="400" numpage="1" nbpage="1">
<JTblView name="JTblView" type="ViewObject" maxfetchsize="999" maxfetchsizeexceeded="false">
<JTblViewRow current="true" type="ViewRow" index="1" business_row_index="1">
<Cletbl precision="6" type="VARCHAR" pk="true">
<business_data>N</business_data>
</Cletbl>
<Codtbl precision="6" type="VARCHAR" pk="true">
<business_data>001</business_data>
</Codtbl>
<Lib1 precision="30" type="VARCHAR">
<business_data>Non</business_data>
</Lib1>
<Lib2 precision="30" type="VARCHAR">
<business_data/>
</Lib2>
<Lir precision="10" type="VARCHAR">
<business_data>Non</business_data>
</Lir>
</JTblViewRow>
<JTblViewRow type="ViewRow" index="2" business_row_index="2">
<Cletbl precision="6" type="VARCHAR" pk="true">
<business_data>O</business_data>
</Cletbl>
<Codtbl precision="6" type="VARCHAR" pk="true">
<business_data>001</business_data>
</Codtbl>
<Lib1 precision="30" type="VARCHAR">
<business_data>Oui</business_data>
</Lib1>
<Lib2 precision="30" type="VARCHAR">
<business_data/>
</Lib2>
<Lir precision="10" type="VARCHAR">
<business_data>Oui</business_data>
</Lir>
</JTblViewRow>
</JTblView>
</VueTable></xmlpres>
</BusinessViewServiceexecuteOut>
</executeResponse>
</soap:Body></soap:Envelope>
At least if I could extract what's in the value of "xmlpres", the better I could do:
<table><row><code></code><libelle></libelle/></row></table>
To then turn it into a json response but I can't see ... I just get all the output or in json stream but with everything , which is not usable.
Create an out-mediation sequence with the following content and attach it to the respective API and try out the scenario. This is to extract the xmlpres content and send that as the response to the client
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="out-sequence">
<!-- extract the xmlpres content and store as OM element -->
<property name="XMLBody"
expression="$body//soap:Body//generic:xmlpres"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:gce="urn:GCE"
xmlns:generic="http://www.generix.fr/technicalframework/businesscomponent/applicationmodule/common" type="OM" />
<!-- pass the extracted property as response body -->
<enrich>
<source type="property" property="XMLBody" />
<target type="body" />
</enrich>
</sequence>
Hope this helps you to extract and send the response accordingly.
I have this canonical structure:
<xsd:complexType name="Document">
<xsd:attribute name="ID" use="optional" type="cdpscm:IDDocument"/>
</xsd:complexType>
<xsd:element name="NationalID" type="cdpscm:NationalID"/>
<xsd:complexType name="NationalID">
<xsd:complexContent>
<xsd:extension base="cdpscm:Document">
<xsd:sequence>
<xsd:element name="Number"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="Passaport" type="cdpscm:Passaport"/>
<xsd:complexType name="Passaport">
<xsd:complexContent>
<xsd:extension base="cdpscm:Document">
<xsd:sequence>
<xsd:element name="Number"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
Who calls my OSB service will cast if the document is a Passaport or a NationalID, but how I get the number value to pass to another service, for example, if I only have the Document element type which doesn't has the number element.
This is the supossed input:
<v24:Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="v2:TouristPerson" ID="5772893">
<v2:Documents>
<v2:Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="v2:Passport">
<v2:Number>03070</v2:Number>
</v2:Document>
</v2:Documents>
</v24:Person>
The real structure is more complex than this, so probably will need to know if I'm working with NationalID or Passaport, a Tourist or a Native Person.
Using Oracle 11g, Eclipse OEPE.
Thanks for the help!
Something like this should work.
declare namespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
let $documents := $body//v24:Person/v2:Documents/v2:Document
for $passport in $documents[#xsi:type="v2:Passport"]
return data($passport/v2:Number)
(: similarly for national IDs :)
I got the following part of code from Odoo community reference website for creating birthday calendar mark ups
.PY file
class birthday_report(osv.osv):
_name = "birthday.report"
_auto = False
_columns = {
'name': fields.many2one('hr.employee','Employee', readonly=True),
'dob' : fields.date('Birthday', readonly=True),
}
def init(self, cr):
tools.drop_view_if_exists(cr, 'birthday_report')
cr.execute("""
create or replace view birthday_report as (
select
h.id as id,
h.id as name,
concat(concat(date_part('Year',current_date),'-'),to_char(h.birthday, 'mm-dd')) as dob
from
hr_employee as h
join
resource_resource as r
on
h.resource_id=r.id
where r.active ='t'
)
""")
birthday_report()
.XML file
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_birthday_report_calendar" model="ir.ui.view">
<field name="name">Employee Birthday</field>
<field name="model">birthday.report</field>
<field name="arch" type="xml">
<calendar string="Birthday" color="name"
date_start="dob"
quick_add="False" avatar_model="hr.employee">
<field name="name"/>
</calendar>
</field>
</record>
<record model="ir.actions.act_window" id="action_birthday_view">
<field name="name">Birthday</field>
<field name="res_model">birthday.report</field>
<field name="view_type">form</field>
<field name="view_mode">calendar</field>
<field name="view_id" eval="view_birthday_report_calendar"/>
<field name="domain">[]</field>
</record>
<menuitem id="menu_birthday" name="Birthday" parent="hr.menu_hr_root" groups="base.group_user"/>
<menuitem id="menu_view_birthday" parent="menu_birthday" action="action_birthday_view" groups="base.group_user"/>
</data>
</openerp>
Error shows up when I navigate to January or previous year December, the following error occurs :
Uncaught Error: '2016-' is not a correct date, datetime nor time.
I am new to sql queries in Odoo, Anyone with suggestions on this would be really grateful. Thanks !!
First, I recommend using || instead of concat. That allows you to do multiple concatenations.
date_part('Year',current_date) || '-' || to_char(h.birthday, 'mm-dd')
Secondly I recommend casting to date, so
(date_part('Year',current_date) || '-' || to_char(h.birthday, 'mm-dd'))::date
Third, what happens if you just use psql and select from the view? Are there malformed dates? Or is something else happening elsewhere in your Python code?
please help me to understand how to write this kind of query with xquery.
I have this .xml:
<auctions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<products>
<product id="1">
<name>Name1</name>
</product>
<product id="2">
<name>Name2</name>
</product>
<product id="3">
<name>Name3</name>
</product>
<product id="4">
<name>Name4</name>
</product>
</products>
<users>
<user username="Kukuk1">
</user>
<user username="Kukuk2">
</user>
<user username="Kukuk3">
</user>
</users>
<bids>
<product id="1">
<bid user="Kukuk1">400</bid>
<bid user="Kukuk2">410</bid>
<bid user="Kukuk1">450</bid>
</product>
<product id="2">
<bid user="Kukuk3">200</bid>
<bid user="Kukuk2">300</bid>
</product>
<product id="3">
<bid user="Kukuk1">150</bid>
</product>
</bids>
</auctions>
and I need to get this output, as follows: The user "Kukuk1" got the products "Name1" (with value "450") and "Name3" (with value "150). The user "Kukuk3" has not won any products. The user "Kukuk2" won the products "Name2".
The elements should be ordered by user ascending and the elements product by value descending, should look like this:
<got>
<user name="Kukuk1">
<product value="450">Name1</product>
<product value="150">Name3</product>
</user>
<user name="Kukuk3"/>
<user name="Kukuk2">
<product value="300">Name2</product>
</user>
</got>
This is what I got so far:
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:item-separator "
";
<got>
{
for $u in (//auctions/users/user)
let $p:= //auctions/products
let $v := //auctions/bids/product
let $max1 := max($v/bid)
let $max2 := max($v/bid[4])
let $got := //auctions/bids/product
let $won-product := $got[#id=$p/product/#id]
order by $u
return
if ($u/#username="Kukuk1") then
(<user name="{fn:string($u/#username)}">
<product value="{$max1}">{fn:string($p/product[1]/name)}</product>
</user>,'
')
else
if
($u/#username="Kukuk3") then
(<user name="{fn:string($u/#username)}">
<product value="{$max2}">{fn:string($p/product[2]/name)}</product>
</user>,'
')
else
if
($u/#username="Kukuk2") then
(<user name="{fn:string($u/#username)}">
<product value="{$max2}">{fn:string($p/product[3]/name)}</product>
</user>,'
')
else ()
}
</got>
And I'm getting this output:
<got>
<user name="Kukuk1">
<product value="450">Name1</product>
</user>
<user name="Kukuk3">
<product value="">Name2</product>
</user>
<user name="Kukuk2">
<product value="">Name3</product>
</user>
</got>
You will need two for loops to achieve the result you describe. In the outer loop you will order the users based on their respective username and in the inner loop you will get the bids and order them by their highest value.
Hence, it should look something like this:
<got>{
for $u in //auctions/users/user
let $username := $u/#username
order by $username
return element user {
$username,
for $product in //auctions/bids/product[bid/#user = $username]
let $highest-bid := max($product/bid)
order by $highest-bid descending
return
if ($product/bid[. = $highest-bid and #user = $username])
then element product {
attribute {"value"} {$highest-bid},
//auctions/products/product[#id = $product/#id]/name/string()
} else ()
}
}</got>
Please note that your example output does not fit your description as Kukuk3 > Kukuk2 and therefore should be order that way. I assumed that your description is correct.
I have an XML like this.
<?xml version="1.0" encoding="UTF-8"?>
<doc>
<ticker> CSGN.VX </ticker>
<stockExchange> NYSE </stockExchange>
<stockDatas>
<stockData>
<date>2015-08-06</date>
<closingPrice>140</closingPrice>
</stockData>
<stockData>
<date>2015-08-07</date>
<closingPrice>140.25</closingPrice>
</stockData>
<stockData>
<date>2015-08-10</date>
<closingPrice>140.75</closingPrice>
</stockData>
</stockDatas>
</doc>
And I will be having similar XMLs for different companies around different years. Now I want to search for documents which have the ticker as CSGN.VX for a particular time duration, so I use this query.
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";
search:search(
'ticker:CSGN.VX AND (dateRange GE "2015-08-07" AND dateRange LE "2015-08-21")',
<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>)
Is there a way where along with the document search, I can also get the closingPrice average for that particular time duration?
I just got a solution but i have a further query, i was looking for a way to implement this using java client API of Marklogic so is there a way to implement search:parse and search:values using Java Client API
I know one way to implement this is through MarklogicXCC API but i wanted to know if there is a way through which these functions can be run using Client API
Provided you have a range index on closingPrice you should be able to do something like this:
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"at "/MarkLogic/appservices/search/search.xqy";
let $query :=
search:parse(
'ticker:CSGN.VX AND (dateRange GE "2015-08-07" AND dateRange LE "2015-08-21")',
<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"
)
return
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
)
Note: I do recommend storing each stockData separately, otherwise the dateRange filter probably won't work as expected.
HTH!