Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Query builder

Avatar

Avatar
Validate 1
Level 1
maheswariv26797
Level 1

Likes

0 likes

Total Posts

16 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
maheswariv26797
Level 1

Likes

0 likes

Total Posts

16 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
maheswariv26797
Level 1

22-12-2020

Hi,

Can anyone please help me on how can i write querybuilder query for the following requirement.

There are pages with the below structure.

/content/project/page1/childpage1/jcr:content/par/1

/content/project/page1/childpage1/jcr:content/par/2

/content/project/page1/childpage1/jcr:content/par/3

 Which means under par, any number of nodes (i.e 1,2,3,4...)can be there and those are of type nt:unstructured and has a property as documentType.

 

Now my requirement is to write a query that checks under  the page path /content/project/page1/ for particular documentType property(Ex:PDF)

Can anyone please help on this.

Thanks,

Mahi

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 3
MVP
Manjunath_K
MVP

Likes

140 likes

Total Posts

188 posts

Correct Reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile

Avatar
Give Back 3
MVP
Manjunath_K
MVP

Likes

140 likes

Total Posts

188 posts

Correct Reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile
Manjunath_K
MVP

22-12-2020

Hi @maheswariv26797,

Try executing below query in QueryBuilder debugger console

 

http://localhost:4502/libs/cq/search/content/querydebug.html

 

type=nt:unstructured

path=/content/project/page1
1_property=documentType
1_property.value=PDF
p.limit=-1

 

Java:

Session session = resourceResolver.adaptTo(Session.class);
Map<String, String> queryPredicateMap = new HashMap<>();
queryPredicateMap.put("type", JcrConstants.NT_UNSTRUCTURED);
queryPredicateMap.put("path", "/content/project/page1");
queryPredicateMap.put("p.limit", "-1");
queryPredicateMap.put("1_property", "documentType");
queryPredicateMap.put("1_property.value", "PDF");
Query query = queryBuilder.createQuery(PredicateGroup.create(queryPredicateMap), session);
SearchResult searchResult = query.getResult();
Iterator<Resource> resourceIterator = searchResult.getResources();
Resource documentResource = null;

while (resourceIterator.hasNext()) {
documentResource = resourceIterator.next();
}

 

Hope this helps!

Answers (0)