I think the issue is in how you write the reference to the element you want to
query. You write
cts:element-attribute-range-query(xs:QName("PUBLICATION-DATE”), but like Chris
is suggesting, you better write xs:QName("PUBLICATION-DATE”) as
fn:QName(“http://www.incisivemedia.com/summary”, “PUBLICATION-DATE”), or you
should declare a namespace prefix in your code, and use that in xs:QName:
declare namespace sum = “http://www.incisivemedia.com/summary”;
xs:QName(“sum:PUBLICATION-DATE")
Cheers
From:
<[email protected]<mailto:[email protected]>>
on behalf of Kari Cowan <[email protected]<mailto:[email protected]>>
Reply-To: MarkLogic Developer Discussion
<[email protected]<mailto:[email protected]>>
Date: Friday, September 22, 2017 at 11:02 PM
To: MarkLogic Developer Discussion
<[email protected]<mailto:[email protected]>>
Subject: Re: [MarkLogic Dev General] Querying DateTime values
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
<[email protected]<mailto:[email protected]>> 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 & 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
<[email protected]<mailto:[email protected]>> 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
<[email protected]<mailto:[email protected]>> 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:
> <[email protected]<mailto:[email protected]>>
> on behalf of Kari Cowan
> <[email protected]<mailto:[email protected]>>
> Reply-To: MarkLogic Developer Discussion
> <[email protected]<mailto:[email protected]>>
> Date: Friday, September 22, 2017 at 4:51 PM
> To: MarkLogic Developer Discussion
> <[email protected]<mailto:[email protected]>>
> 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</summary: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
> [email protected]<mailto:[email protected]>
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
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
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general