Hi, Eric:

In MarkLogic 9, you could create a TDE template to project rows into the index 
with columns for the subject and date_taken.

Then, using SQL, SPARQL, or Optic, you could group on the subject and count the 
rows as filtered by the date.

In MarkLogic 8, you could set up a range indexes on the subject and date_taken 
and use a values query on the subject range index, counting document frequency 
and filtering on the date.


Hoping that's orienting,


Erik Hennum


________________________________
From: [email protected] 
[[email protected]] on behalf of Ladner, Eric 
(Eric.Ladner) [[email protected]]
Sent: Thursday, August 24, 2017 2:30 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Noob query question..

Thank you.  I will play with this in my development environment tomorrow.  I 
don’t quote see how it’s getting the counts per subject, though.

For reference.. the structure is similar to this:

<note>
   <subject>Test Subject</subject>
  <date_taken>2017-04-01T15:32:00</date_taken>
  <content>Blah, blah</content>
</note>

There would be many notes, obviously and the output would ideally be something 
like (not married to that output, but some output showing the counts for each 
subject over that time range).

<counts>
  <countItem>
     <subject>Test Subject</subject>
     <count>2</count>
  </countItem>
  <countItem>
    <subject>Subject 2</subject>
    <count>4</count>
  </countItem>
   ...
</counts>

Eric Ladner
Systems Analyst
[email protected]<mailto:[email protected]>


From: [email protected] 
[mailto:[email protected]] On Behalf Of Sam Mefford
Sent: August 24, 2017 15:59
To: MarkLogic Developer Discussion <[email protected]>
Subject: [**EXTERNAL**] Re: [MarkLogic Dev General] Noob query question..

I should point out that this is not the fastest way to do it.  A faster way 
would be to index "date-taken" as a dateTime element range index and use 
cts:search with cts:element-range-query.

Sam Mefford
Senior Engineer
MarkLogic Corporation
[email protected]<mailto:[email protected]>
Cell: +1 801 706 9731
www.marklogic.com<http://www.marklogic.com>

This e-mail and any accompanying attachments are confidential. The information 
is intended solely for the use of the individual to whom it is addressed. Any 
review, disclosure, copying, distribution, or use of this e-mail communication 
by others is strictly prohibited. If you are not the intended recipient, please 
notify us immediately by returning this message to the sender and delete all 
copies. Thank you for your cooperation.
________________________________
From: 
[email protected]<mailto:[email protected]>
 [[email protected]] on behalf of Sam Mefford 
[[email protected]]
Sent: Thursday, August 24, 2017 2:56 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Noob query question..
XQuery is an extension of XPath.  Here's an example in XPath.  These things are 
easiest to understand if we know the structure of your docs.  Suppose I insert:

xdmp:document-insert("test.xml", 
<note><date-taken>2015-01-01</date-taken></note>)

I could find the count of docs more than two years old like this:

count(/note[fn:days-from-duration(fn:current-date() - date-taken) > (365 * 2)])


Sam Mefford
Senior Engineer
MarkLogic Corporation
[email protected]<mailto:[email protected]>
Cell: +1 801 706 9731
www.marklogic.com<http://www.marklogic.com>

This e-mail and any accompanying attachments are confidential. The information 
is intended solely for the use of the individual to whom it is addressed. Any 
review, disclosure, copying, distribution, or use of this e-mail communication 
by others is strictly prohibited. If you are not the intended recipient, please 
notify us immediately by returning this message to the sender and delete all 
copies. Thank you for your cooperation.
________________________________
From: 
[email protected]<mailto:[email protected]>
 [[email protected]] on behalf of Ladner, Eric 
(Eric.Ladner) [[email protected]]
Sent: Thursday, August 24, 2017 2:24 PM
To: MarkLogic Developer Discussion
Subject: [MarkLogic Dev General] Noob query question..
I’m still rather new to MarkLogic and apparently have a lot to learn.  When 
doing research on a proof of concept, I ran across a situation that would be 
trivial to solve in SQL, but I’m having problems wrapping my head around how to 
do that in XQuery.  Or, is XQuery even the right place for this?

Basically, the number of notes per subject for any note that’s less than two 
years old.  If I was to do this in SQL, it’d look something like:

   select subject, count(*) from notes where date_taken > sysdate-(365*2) group 
by subject;

There’s some additional WHERE clause stuff for filtering, but on average, the 
number of results shouldn’t be large.

Any guidance on building up more complex queries like this?  The documentation 
is semi-helpful, but the examples it gives for usage are usually very 
simplistic.

Eric Ladner
Systems Analyst
[email protected]<mailto:[email protected]>


_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to