Re: [MarkLogic Dev General] Search by age wise from dob property

2017-05-22 Thread Justin Makeig
const person = { dob: xs.date("1979-02-03") };
const thrirtyYearsAgo = fn.currentDate().subtract(xs.yearMonthDuration("P30Y"));
person.dob < thrirtyYearsAgo; // true

You can do date math with xs.duration types. In the above case, I'm subtracting 
30 years from the current date. xs.date.prototype.subtract() returns an 
xs.date. You can compare that xs.date to any other xs.date. To do this 
comparison in MarkLogic's indexes you'll need to create a range index 
. A range index, 
as its name implies, queries efficiently for ranges of typed values, for 
example, dates less than thirty ago from today.

cts.rangeQuery(cts.jsonPropertyReference('dob'), '<', thrirtyYearsAgo); // 
requires a range index of type xs:date on the dob JSON property


Justin


> On May 22, 2017, at 1:08 PM, Shiv Shankar  wrote:
> 
> Hi,
> There is a dob json property in the documents and I need to search on dob 
> based on age wise i.e age > 30, age >30 and age <50.  Any samples to 
> calculate age and compare in the search queries?
> 
> Thanks
> Shan.
> 
> 
> 
> ___
> General mailing list
> General@developer.marklogic.com
> Manage your subscription at: 
> http://developer.marklogic.com/mailman/listinfo/general

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


[MarkLogic Dev General] Search by age wise from dob property

2017-05-22 Thread Shiv Shankar
Hi,
There is a dob json property in the documents and I need to search on dob
based on age wise i.e age > 30, age >30 and age <50.  Any samples to
calculate age and compare in the search queries?

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