AEM - Adding date range in QuerybuilderAPI

P_Vishnu

24-08-2020

I have the below query I am using in /libs/cq/search/content/querydebug.html to check the results

 

1_property=test 1_property.value=active 2_property=status 2_property.value=worked p.hits=selective p.limit=-1 path=/home/users type=rep:User

 

This is working and i am getting results .Now I need the records who has a property registrationCompletedDate = 2020-08-09 to know the users registered on 9th.

Can someone help how I can add this date range in my query?

I tried this, but did not work

 

daterange.upperBound=2020-08-10
daterange.lowerBound=2020-08-9
daterange.property=registrationCompletedDate

 

AEM querybuilder

Accepted Solutions (1)

Accepted Solutions (1)

Vijayalakshmi_S

MVP

24-08-2020

Hi @P_Vishnu,

Given that we are looking for exact match on a Date property, we can bring in the search results with "property" predicate itself instead of Date related predicates like daterange/relativedaterange/dateComparsion where first two works on range and last works on comparison of two Date type properties.

Try the below sample query and let know if it works

To bring in all pages which has property of type "Date" + name "registrationCompletionDate" + value like 2020-08-09 (in jcr:content of page)

path=/content/we-retail
type=cq:Page
property=@jcr:content/registrationCompletionDate
property.value=2020-08-09% // assuming Time is different and date is 2020-08-09
property.operation=like

Answers (2)

Answers (2)

berliant

Employee

24-08-2020

Assuming that the property "registrationCompletedDate' in with rep:User node, the query should be similar to 

path=/home/users
type=rep:User

daterange.property=registrationCompletedDate
daterange.upperBound=2020-08-19T23:59:59.000-04:00
daterange.lowerBound=2020-08-19T00:00:00.000-04:00

p.limit=-1

 

Now, you need to have an index for registrationCompletedDate, it should be similar to

- compatVersion = 2
- async = "async"
- jcr:primaryType = oak:QueryIndexDefinition
- evaluatePathRestrictions = true
- type = "lucene"
+ indexRules
+ rep:User
+ properties
+ registrationCompletedDate
- name = "registrationCompletedDate"
- propertyIndex = true

 

 

berliant_0-1598301950572.png

 

berliant_1-1598302015327.png

 

 

berliant

Employee

24-08-2020

Check this sample:

path=/content
type=cq:PageContent
group.p.or=true
group.1_daterange.property=cq:lastModified
group.1_daterange.upperBound=2017-04-21T23:59:59.000-04:00
group.1_daterange.lowerBound=2017-04-21T00:00:00.000-04:00

group.2_daterange.property=jcr:created
group.2_daterange.upperBound=2017-04-21T23:59:59.000-04:00
group.2_daterange.lowerBound=2017-04-21T00:00:00.000-04:00
p.limit=-1