Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Run AEM Query-builder query in batch

Avatar

Level 2

I have the below working query

path=/content/dam
type=sling:OrderedFolder
nodename=[0-9][0-9][0-9][0-9]-([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9][0-9][0-9])
property=jcr:content/metadataprofile
property.operation=exists
property.value=false
p.limit=-1

It runs on entire Path=/content/dam, so it traverse all nodes for about 20 minutes and gives results.

How can i make it in batches when using query-builder API code-wise, like - traverse 1000 nodes and do-something code-wise and then continue with query and traversing next 1000 nodes and so-on ? Is it possible ?
Thanks in advance.

Topics

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
3 Replies

Avatar

Correct answer by
Community Advisor

Hi,

You can combine offset, guessTotal and limit

https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/querybuilder-api.html



Arun Patidar

Avatar

Level 2
Should i give P.limit and p.guessTotal as some random number OR should I assign guessTotal as SearchResult.getTotalMatches() ? As i don't want my code to stop after certain number of nodes and want it to run completely without missing any nodes. Can you share sample java code using implementing that?

Avatar

Community Advisor

you should use guess Total. Always set guessTotal to true unless you know your result set. This will make the result set small and counting it will be fast.

Use offset to set starting and ending point of result set.

 

int hits = 10;
int start = 0;
int offset = 3;// for example 4th set of result.

predicateMap.put("p.guessTotal", String.valueOf(offset + (6 * hits)));
Query query = queryBuilder.createQuery(PredicateGroup.create(predicateMap), session);
if (offset >= 0) {
 start = offset;
}
query.setStart(start);
query.setHitsPerPage(hits);


Arun Patidar