Expand my Community achievements bar.

SOLVED

AEM - Adding date range in QuerybuilderAPI

Avatar

Level 2

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

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

6 Replies

Avatar

Employee

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

Avatar

Level 2

@berliantI added the below to my query

 

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

 

But it is not giving me any results

Avatar

Employee
you are challenging a custom property registrationCompletedDate, it is "Date" Type or is it a "String" Type?

Avatar

Employee

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

 

 

Avatar

Correct answer by
Community Advisor

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