[MarkLogic Dev General] Querying DateTime values

Kari Cowan kcowan at alm.com
Fri Sep 22 14:02:19 PDT 2017


Let me get your opinion on this.  I confirmed that there IS a dateTime
element-attribute range index.

Where the query works correctly, the data is written like this
representation:

<DOC-SUMMARY xmlns="http://www.incisivemedia.com/summary">
<PUBLICATION-DATE date="2017-08-09"
datetime="2017-08-09T15:14:00-04:00">2017-08-09
15:14:00:000</PUBLICATION-DATE>
</DOC-SUMMARY>

Where it fails, the data is written this way - note the namespace precedes
the declaration - which seems wrong to me.

If it's right or wrong, can you advise if that needs to be updated or if
there's a way to run the query to check a date range, returning docs within
say the last 10 days only?

<summary:DOC-SUMMARY xmlns:summary="http://www.incisivemedia.com/summary">
<summary:PUBLICATION-DATE date="2017-09-21"
datetime="2017-09-21T17:47:00Z">2017-09-21T17:47:00Z</summary:PUBLICATION-DATE>
</summary:DOC-SUMMARY>

On Fri, Sep 22, 2017 at 1:05 PM, Kari Cowan <kcowan at alm.com> wrote:

> Ahh, once i fixed the misplaced paren, I can get back a proper error that
> tells me something more useful -- No dateTime element-attribute range index
> for fn:QName("", "PUBLICATION-DATE") fn:QName("", "datetime")
>
> Thanks! - I think I know where to go from here :)
>
> XDMP-ELEMATTRRIDXNOTFOUND: cts:search(fn:collection(),
> cts:and-query((cts:directory-query("/data-sources/sbm/", "infinity"),
> cts:or-query((cts:element-query(xs:QName("sum:PUBLICATION-NAME"),
> cts:word-query("BenefitsPro.com", ("lang=en"), 1), ()),
> cts:element-query(xs:QName("sum:PUBLICATION-NAME"),
> cts:word-query("CUTimes", ("lang=en"), 1), ()), cts:element-query(xs:QName("sum:PUBLICATION-NAME"),
> cts:word-query("Treasury &amp; Risk", ("lang=en"), 1), ()), ...)),
> cts:element-attribute-range-query(fn:QName("", "PUBLICATION-DATE"),
> fn:QName("", "datetime"), ">=", xs:dateTime("2017-08-23T23:59:00Z"), (),
> 1)), ())) -- No dateTime element-attribute range index for fn:QName("",
> "PUBLICATION-DATE") fn:QName("", "datetime")
>
> On Fri, Sep 22, 2017 at 8:15 AM, Christopher Hamlin <cbhamlin at gmail.com>
> wrote:
>
>> I'm not sure what is the real problem.
>>
>> xs:dateTime ('2003-08-01T08:00:00Z') > xs:dateTime (fn:current-date()
>> - xs:dayTimeDuration("P30D"))
>> ,
>> xs:dateTime ('2017-09-28T00:00:00-04:00') > xs:dateTime
>> (fn:current-date() - xs:dayTimeDuration("P30D"))
>>
>> return false and true, no failure.  What type is the index, and what
>> is the failure?
>>
>> On Fri, Sep 22, 2017 at 11:10 AM, Geert Josten
>> <Geert.Josten at marklogic.com> wrote:
>> > Hi Kari,
>> >
>> > Looks like you misplaced one of the parentheses. Make sure to wrap the
>> > string "2017-09-22T08:00:00Z” in xs:dateTime(..) before you try to
>> substract
>> > the duration. In provided query you have the xs dateTime cast wrapping
>> both
>> > current-date and the duration.
>> >
>> > Cheers,
>> > Geert
>> >
>> > From: <general-bounces at developer.marklogic.com> on behalf of Kari Cowan
>> > <kcowan at alm.com>
>> > Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.c
>> om>
>> > Date: Friday, September 22, 2017 at 4:51 PM
>> > To: MarkLogic Developer Discussion <general at developer.marklogic.com>
>> > Subject: [MarkLogic Dev General] Querying DateTime values
>> >
>> > I need some expert tips on this bug.
>> >
>> > cts:element-attribute-range-query(xs:QName("PUBLICATION-DATE
>> "),xs:QName("datetime"),
>> > ">=", xs:dateTime(fn:current-date() - xs:dayTimeDuration("P30D")))
>> >
>> > The above query works fine when the publication-date is in this format:
>> > <PUBLICATION-DATE date="2017-09-28"
>> > datetime="2017-09-28T00:00:00-04:00">2017-09-28
>> > 00:00:00:000</PUBLICATION-DATE>
>> >
>> > But it fails when
>> > <PUBLICATION-DATE date="2003-08-01"
>> > datetime="2003-08-01T08:00:00Z">2003-08-01T08:00:00Z</summar
>> y:PUBLICATION-DATE>
>> >
>> > The datetime format is different, but if I manipulate the current-date
>> to
>> > match that format, the query will fail with this message:
>> >
>> > [1.0-ml] XDMP-EXPR: (err:XPTY0004) "2017-09-22T08:00:00Z" -
>> > xs:dayTimeDuration("P30D") -- Invalid expression
>> >
>> > How would I write the query to properly compare the dates?
>> >
>> > The goal above was to return content from the last 30 days.
>> >
>> >
>> >
>> >
>> >
>> > _______________________________________________
>> > General mailing list
>> > General at developer.marklogic.com
>> > Manage your subscription at:
>> > http://developer.marklogic.com/mailman/listinfo/general
>> >
>> _______________________________________________
>> General mailing list
>> General at developer.marklogic.com
>> Manage your subscription at:
>> http://developer.marklogic.com/mailman/listinfo/general
>>
>
>
>
> --
>
> Kari Cowan :: Web Developer :: ALM Media
>
> 1035 Market St. Suite 550, San Francisco, CA 94103
>
> iPhone/Text/FaceTime: +1 4157 444 762
>



-- 

Kari Cowan :: Web Developer :: ALM Media

1035 Market St. Suite 550, San Francisco, CA 94103

iPhone/Text/FaceTime: +1 4157 444 762
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20170922/e2192101/attachment-0001.html 


More information about the General mailing list