For functionalities like full text search, retrieve content based on certain property or conditions associated with property/to avoid iterations on huge volume of content under the root, we write query based logic in AEM.
Languages supported :
1.Created using AEM Query Builder API. - com.day.cq.search.*
2.From development point of view, we need to be aware of standard OOB predicates to arrive at XPATH query.
1.JCR-SQL2 queries are created using QueryManager - javax.jcr.query.QueryManager
2.QueryManager is acquired through JCR Session - session.getWorkspace().getQueryManager()