Jon,

Is this for UI development, back-end data processing? If UI front end, and if 
you have some flexibility with your data structure, you could :

1)      create another element that is just the date component of the datetime

2)      create and xs:date range index

3)      reference this in search:search in the options node as 
UI_FIELDNAME_FOR_DATE

4)      also in options node, make joiner elements for LT/GT/etc

5)      then your input string 'UI_FIELDNAME_FOR_DATE GT 2012-03-06'

Looking at the total-time in search-metrics element of the search:search 
response object, this works as fast as any UI field. For back-end data 
processing, creating a UI like string would probably be excessive, but I'd 
think that an xs:date range index would fast.

However, I wouldn't recommend creating a range index if you must retain the 
entire datetime string down to the millisecond. This could create an awful 
index where there would one 'item' per index entry.


Matthew




From: [email protected] 
[mailto:[email protected]] On Behalf Of Jonathan Cook
Sent: Friday, March 09, 2012 10:36 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Comparing Dates

Thanks, your xpath select doesn't work so I ended up with this:
let $results := /bbc:*[
    /bbc:*/bbc:itemMeta/bbc:assetTypeCode[text()=$asset_type_code] and 
/bbc:*/bbc:itemMeta/bbc:lastPublished[text() >= $asset_publication_date_start 
and text() < $asset_publication_date_end ]
    ]

I don't think it is particularly efficient

Thanks
Jon


On 09/03/2012 11:21, "Geert Josten" <[email protected]> wrote:
Hi Johnathan,

How about something like:

let $asset_type_code := "STY"
let $asset_creation_date := "20111017"
let $asset_creation_date_start := xs:dateTime(fn:replace($asset_creation_date, 
"^(\d{4})(\d{2})(\d{2})$", "$1-$2-$3T00:00:00"))
let $asset_creation_date_end := $asset_creation_date_start + 
xs:dayTimeDuration("P1D")


return
    doc()[//assetTypeCode = $asset_type_code][//firstCreated >= 
$asset_creation_date_start][//firstCreated < $asset_creation_date_end]/*


It might perform better though if you'd rewrite to for instance:

cts:search(
    doc(),
    cts:and-query((
        cts:element-value-query(xs:QName("assetTypeCode"), $asset_type_code),
        cts:element-range-query(xs:QName("firstCreated"), ">=", 
$asset_creation_date_start),
        cts:element-range-query(xs:QName("firstCreated"), "<", 
$asset_creation_date_end)
    ))
)/*


This requires a few indexes though..

Kind regards,
Geert


Van: [email protected] 
[mailto:[email protected]] Namens Jonathan Cook
Verzonden: donderdag 8 maart 2012 17:59
Aan: MarkLogic Developer Discussion
Onderwerp: [MarkLogic Dev General] Comparing Dates

Hi,

I wondered what the best way to compare dates using mark logic xquery was?

My query looks like this at the moment:

import module namespace xinc = "http://marklogic.com/xinclude"; at 
"/MarkLogic/xinclude/xinclude.xqy";

let $asset_type_code := "STY"
let $asset_creation_date := "20111017"

let $results := /*[
    /*/itemMeta/assetTypeCode[text()=$asset_type_code] and 
/*/itemMeta/firstCreated[text()='2011-10-17T14:47:52+00:00']
    ]

return $results

However what I would like to do is use the $asset_creation_date variable which 
would be of format yyyyMMdd and see if it equals the first part of the 
firstCreated element which is in a different format as above? There doesn't 
seem to be many date time functions and also I'm not sure if I'm going about 
this slightly the wrong way or if I would have to do it in a second FLOWR 
statement using some string comparison?

Thanks
Jon



http://www.bbc.co.uk
This e-mail (and any attachments) is confidential and may contain personal 
views which are not the views of the BBC unless specifically stated.
If you have received it in error, please delete it from your system.
Do not use, copy or disclose the information in any way nor act in reliance on 
it and notify the sender immediately.
Please note that the BBC monitors e-mails sent or received.
Further communication will signify your consent to this.
________________________________
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general


http://www.bbc.co.uk
This e-mail (and any attachments) is confidential and may contain personal 
views which are not the views of the BBC unless specifically stated.
If you have received it in error, please delete it from your system.
Do not use, copy or disclose the information in any way nor act in reliance on 
it and notify the sender immediately.
Please note that the BBC monitors e-mails sent or received.
Further communication will signify your consent to this.
This electronic message contains information generated by the USDA solely for 
the intended recipients. Any unauthorized interception of this message or the 
use or disclosure of the information it contains may violate the law and 
subject the violator to civil or criminal penalties. If you believe you have 
received this message in error, please notify the sender and delete the email 
immediately.
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to