[MarkLogic Dev General] Ignoring empty/null values while search

2017-05-24 Thread Gary Vidal
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


[MarkLogic Dev General] Ignoring empty/null values while search

2017-05-23 Thread Shiv Shankar
Hi,
How can I skip empty/null values as my dob property has empty ("") string
for some of the documents and below error is giving error XDMP-LEXVAL:
xs.date("") -- Invalid lexical value ""
Query:
cts.search(cts.andQuery([cts.jsonPropertyRangeQuery("dob", '>',
fn.currentDate().subtract(xs.yearMonthDuration("P25Y"))),cts.collectionQuery("col-1")]));

And
Q2: Any sample for group-by age by extracting date from dob?

Thanks
Shan.
___
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general