Monday, 18 September 2023

Query builder in AEM(Basic Structure)

  • If we talk about Search API in AEM there is Two main options available.
    • QueryBuilder
    • JCR SQL

  • What is Query Builder?
     The Query Builder in AEM is a framework and toolset that allows         developer and content authors to create and execute complex             queries to retrieve content from the AEM repository. It provides       a simple and efficient way to search for and access content based       on various criteria.                                              

  • How you can Write and execute Query Builder?
    There is a Console available in AEM where, we can write and test      our Query.
    Query Builder debugging tool allows you to interactively create,      test, and debug queries 
   URL :http://localhost:4502/libs/cq/search/content/querydebug.html 
  • Where does the Query Builder store data in the JCR.?
The data in the JCR is stored as a hierarchical structure of nodes and properties.
/libs/cq/search/content/querydebug

There is a console to test your query using this path http://localhost:4502/libs/cq/search/content/querydebug.html



  • When you write the query builder first you have to define what kind of node you want to search using as a generic term as a node you can define page, asset some any kind of node so whatever the primary type available in AEM you can search that any        available primary type so, first we have to define type.
  • In type we have to decide what you want to search suppose, I want to search pages so, the primary type of pages are cq:Page.


  • So, using this query we found all pages available in my repository .
  • But it's not right query total no of pages is 1750 but, it is showing only 10 pages name.
  • So, the solution is firstly we define the path and the path query is type=cq:Page


  • show 19 pages and the result is show 10 For change this behavior we can define One parameter i.e: p.limit.
  • p.limit can define how many results we want to search.
  • Basically, p.limit will be used when we implement Pagination.

  • for eg: we put p.limit=5, than Number of hits is 19, but results are 5.
  • If we want all results display than, we write p.limit=-1.
  • If we want some specific template so, let's see how we add any property and how we will search based on property.
  • property=cq:template and than, property.value= whatever the property of value.



  • AS soon as hit that search button the number of hits is 0. so, let's see what is the issue here.
  • We are trying to search cq:Page we are using node it means the page we should have a property so, if we go there in repository and check this node does have property called cq:template that is the reason result showing 0.
  • Let 's see how to resolve this problem if we see all the data store in jcr:content  and this has primary type cq:PageContent





  • In this Query might be missing some value than we are searching page not page content so keep type=cq:Page itself and search the relative path [It means properties on related path] It means /page there is a node jcr:content than we add relative path.

  • In each hit having a page rather than the page content.
  • If we want to search multiple of same property than using jcr:title.

  • Only single property we defining multiple value using property.1_value= title name.
  • By default it has or value if we want to make it end than, we are using propery.and=false by default it is false, if we make it true than the result is 0.
  • Because title does not have both 

  • Now we want to use multiple properties.
  • For multiple properties we are using prefix before properties rather than before value.

  • Suppose we want or condition it means either template is home or title is xml.
  • So, for that we have define groups



  • If there is no homepage template, why is the number of hits not 0? Let's see what the reason is
  • It is coming on search because the title is xml present.

  • How to know the data of each search result?
    • There is a option of JSON QueryBuilder Link click on this so, we will find in json what data is coming so it will giving all results. 



  • If we want order of these last modified date so we search orderby=@jcr:content/cq:lastModified


  • By default it is an ascending order.
  • If we want descending order so we search orderby.sort=desc.

Thanks
Matri sharma

No comments:

Post a Comment

Servlet in AEM/Sling Servlet

  What is Servlet? A servlet is a Java class that runs on the server side where the application resides. It acts as a middle layer between t...