Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

In Query Builder JSON Response Results and Total are coming as different Values

Avatar

Level 4

I am using Query Builder API to query through the documents matching certain criteria, Here is the sample query from query debug tool,

path=/content/dam/mchp/documents
type=dam:Asset
property.and=true
1_property=jcr:content/metadata/mchp:document-category
1_property.value=documents:product-documents/code-examples
2_property=jcr:content/metadata/mchp:document-application
2_property.operation=exists
p.hits=selective
p.properties=jcr:title
p.nodedepth=5
p.limit=-1

 

When I see the result as JSON response , 

PoovithaSelvaraj_0-1676026047520.png

 

Both Results and Total are different values. In API also results are coming as 283 only. 
Wanted to know what is the difference between total and result ? and Y it is coming as different values?

 

Thanks in Advance.

1 Accepted Solution

Avatar

Correct answer by
Level 5

Hi @PoovithaSelvaraj 

Can you try adding p.guessTotal=1000 and remove p.limit ? so it will read up to 1000, to get exact total. But if total is more than 1000, then 'more' will be true and you need to extract the result using offset until 'more' gets false.

View solution in original post

6 Replies

Avatar

Community Advisor

Hi @PoovithaSelvaraj 

 

Ideally the query run in the query builder and Query builder API should return the same hits. Can you check if you are missing any properties like p.limit etc which is making the results come low?

 

Thanks,
Kiran Vedantam

Avatar

Level 4

I have added p.limit to the query still it is not matching.

 

Thanks,

Poovitha S

Avatar

Level 5

what value added as p.limit and what's the value of more field? Please share the query output.

Avatar

Level 4

Hi @Chandra_Hire , 

p.limit i am setting as -1. 

"success": true,

"results": 262,

"total": 970,

"more": false,

"offset": 0,

Avatar

Correct answer by
Level 5

Hi @PoovithaSelvaraj 

Can you try adding p.guessTotal=1000 and remove p.limit ? so it will read up to 1000, to get exact total. But if total is more than 1000, then 'more' will be true and you need to extract the result using offset until 'more' gets false.

Avatar

Level 5

Hi @PoovithaSelvaraj 

'total' in JSON result is an outcome of SearchResult.getTotalMatches() method call and Returns the total number of matches or the total as far as it is known. This depends on the query, i.e. it might just retrieve the minimum necessary up to getStartIndex() + getHitsPerPage(). In your case 'more' is false it means getTotalMatches() returned the exact number of Hits.
Also, 'result' in JSON is an outcome of SearchResult.getHits() and which is a List of Hits to display on the result page. though p.limit is set to -1 to display all the results (total filed in json), Querybuilder by default sets the number of hits to be returned as 'result' (getHits()) based on the query. This can be verified with JCR API SearchResult.getHitsPerPage() and should return the number equal to the number displayed in 'result' field of JSON. In your case it should be 283. 

You can add pagination (offset/limit/guessTotal) to traverse all Hits (results). Hope this helps.

 

Have a look for reference

SearchResult (The Adobe AEM Quickstart and Web Application.)

Query Builder API | Adobe Experience Manager