Showing posts with label Query Builder. Show all posts
Showing posts with label Query Builder. Show all posts

Sunday, 6 December 2015

Query Builder

Search is always the backbone of many functionalities in an AEM application . It becomes quite critical in Business scenarios to implement the most Optimized Query which fetches the best possible result. To perform search in AEM , Query Builder is highly recommended over simple SQL / XPATH query statements. The Query Builder , if used correctly, will solve all your query implementations and would be a handy way to Optimize your queries for better performance of the page. Through this Blogpost , I would explain the basics of Query builder and then would go to advanced concepts , focusing at each point how you may create any search scenario to Query Builder Predicate form. I hope this post will solve all your Search performances related hurdles in AEM.

What is Query Builder?

Query Builder is an API which can be used to create Search queries in JAVA content repository. It is extensible tool by which you may add/remove various predicates in a query using this API. The best way to create predicates is using the Query Builder Debugging Tool : /libs/cq/search/content/querydebug.html . Try to implement your Business use case in the Predicate form using this debugger, Optimize the query and then implement it in the code.

Creating Adobe CQ OSGi bundles that use the Query Builder API

Discusses how to create an OSGi bundle that contains the AEM Query Builder API. This OSGi operation contains application logic to search the AEM repository. This article also discusses how to create a web page that invokes an operation exposed by the OSGi bundle and display the results in a grid control.    
This article uses an Adobe Maven Archetype project to build an OSGi bundle. If you are not familiar with an Adobe Maven Archetype project, it is recommended that you read the following article: Creating your first AEM Service using an Adobe Maven Archetype project.
This article has been updated to replace the use of a SlingRepository instance with a ResourceResolverFactory instance. TheResourceResolverFactory is used to create a Session instance that is required to use the AEM Query Builder API. Now a Session instance is created by using the adaptTo method:
resourceResolver.adaptTo(Session.class);
This article has been updated to use this Maven command to build the OSGi bundle:
mvn archetype:generate -DarchetypeRepository=https://repo.adobe.com/nexus/content/groups/public/ -DarchetypeGroupId=com.day.jcr.vault -DarchetypeArtifactId=multimodule-content-package-archetype -DarchetypeVersion=1.0.2 -DgroupId=custom.querybuilder -DartifactId=querybuilder -Dversion=1.0-SNAPSHOT -Dpackage=custom.querybuilder -DappsFolderName=myproject -DartifactName="My Project" -DcqVersion="5.6.1" -DpackageGroup="My Company"

cq5-querybuilder-adapttoberlin


Read More >>

Content Finder - Query Builder

Use QueryBuilder HTTP API syntax to drive ContentFinder queries instead of more restrictive GQL.
How to Use
  • Install the ACS AEM Commons package
  • Create a new Content Finder Tab JS file
  • Update the contentfindertab config JS object to include:
    • url: “/bin/wcm/contentfinder/qb/view.json”
    • baseParams: { .. }
      • JS object representing the QueryBuilder API key/value pairs used to drive all of the ContentFinder Tab’s queries
      • If no baseParams are set then the suggestField will populate the query param
    • getParams: { .. }
      • JS object representing the dynamic QueryBuilder API key/value pairs used to drive all of the ContentFinder Tab’s queries (baseParams will be used in conjunction with these)

Query Builder samples

AEM comes with a Query Debugger tool at:
/libs/cq/search/content/querydebug.html
You can execute search queries on the JCR (Java Content Repository) using this tool.  For example, to search for all DAM assets in /content/dam/geometrixx, execute the following query:
type=dam:Asset
path=/content/dam/geometrixx
See screenshot below:
image
Running this search query should produce a result such as follows:
image
You can execute more complicated search queries as well.  For example, to search for all DAM assets in /content/dam/geometrixx with the string “.png” in the node name and to to sort the results in the descending order of when the node was last modified, execute the following query:
type=dam:Asset
path=/content/dam/geometrixx
nodename=*.png
[email protected]:content/jcr:lastModified
orderby.sort=desc
More information here.  Excellent blog entry by Thomas Joseph on Oak indexes here.
Other examples:
How many audit events have accumulated:
type=cq:AuditEvent
path=/var/audit
How many unique users have logged in to AEM in the past 12 hours?
A user who has logged in from three different IP addresses (home office, work, mobile phone) will be counted three times.
type=rep:Token
path=/home/users
How many web pages are in the AEM system?
type=cq:Page
path=/content
How many tags have been defined?
type=cq:Tag
path=/etc/tags
How many total users are defined in the AEM system?
type=rep:User
path=/home/users
How many user groups are defined?
type=rep:Group
path=/home/groups
How many Client Libraries?
type=type=cq:ClientLibraryFolder
path=/etc

Read More 

Query Builder

  • QueryBuilder is an API used to build Queries for Query Engine.
  • The generated queries are compatible with HTML forms also.
  • Allows us to add and remove conditions
  • Allows us to copy and paste of Queries
  •  Easily extensible
  • This QueryBuilder resides at server side and accepts a query description, creates and runs an XPath query.
  • The Query Description is simply a set of predicates.
  • Predicates are nothing but conditions. For each predicate type there is an evaluator component PredicateEvaluator that knows how to handle that specific predicate for XPath, filtering and facet extraction.
  • Standard Predicates:
    •  path
    •  property
    • type
    • fulltext
    •  range
    •  daterange
    • nodename
    •  similar
    • tagid & tag
    • language
    • event
    •  Also we can have the following predicates: 
      • group of predicates
      • like brackets 
      • order by predicates

Wednesday, 18 November 2015

Creating a Sightly component that uses the AEM QueryBuilder API

You can create an Adobe Experience Manager (AEM) 6 Sightly  component that can be used within the AEM Touch UI view. Furthermore, you can use Sightly and the QueryBuilder API to develop the AEM component that displays AEM JCR data.

Sightly is an AEM  template language that can be used to replace the use of JSP when developing an AEM component. Sightly helps you to separate your design from your application logic.  In this use case, the Sightly logic is located within an HTML file and displays the result set. The Java part of the Sightly component uses the QueryBuilder API.


To read this AEM community article, click https://helpx.adobe.com/experience-manager/using/sightly_querybuilder.html.