Shiv,

The problem is quite simple to solve.  The first thing is to determine what
is empty.  Mostly empty can be the non-existence of the element and second
an empty element.  Simply just add an additional negated
 cts.notQuery(cts.propertyValueQuery(...)).  This will filter out empty dob
documents during projection of results.

Q2.

What you are expecting cannot be done simply because age is a temporal
value and MarkLogic operates on stored values.  So you cannot simple
determine age without coding it for each document.  But lets make some
assumptions that dob is just xs:date value and the simplest way to extract
out each bucket is quite simple:

xquery version "1.0-ml";
(:Get current year:)
let $today := fn:current-date()
(:Get Current Range of DOB to get years:)
let $dob-ranges := cts:value-ranges(
   cts:json-property-reference("dob"),
   ()
)
(:Get range of years to calculate
  Any arithmetic between to dates results in a duration.
:)
let $years       := fn:years-from-duration($today -
$dob-ranges/cts:minimum-value) to fn:years-from-duration($today -
$dob-ranges/cts:maximum-value)
let $year-dates  := $years ! ($today -
xs:yearMonthDuration(fn:concat("P",.,"Y")))
let $year-ranges := cts:value-ranges(
   cts:json-property-reference("dob"),
   $year-dates
   )
let $year-map := json:object-define($years ! fn:string(.))
return (
(:Iterate all year-ranges and calculate age :)
   for $yr in $year-ranges
   let $year := fn:years-from-duration($today - $yr/cts:maximum-value)
   return
      map:put($year-map,$year,cts:frequency($yr)),
    $year-map
)

(:Enjoy:)
_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to