I have seen in adobe API documentation QueryBuilder Service which can be called by URLs for many query options, this returns JSON based responses. Very well. I wan to use this in java API. I have found some examples and tried in eclipse but some thing i dont know that how to get the Service "sling" as in given code below: OR in other words how to make a QueryBuilder Java object.
Any specific JAR i needed or i need to install Apache SLING on my PC i am not sure any one who can share this will be helpful as i am new to CQ5 and has no idea.
The example code is as below:
Repository repository = JcrUtils.getRepository(SERVER);
SimpleCredentials credentials = new SimpleCredentials(USERNAME, PASSWORD.toCharArray());
Session session = repository.login(credentials);
System.out.println("got session: " + session);
/*HERE SLING IS THE PROBLEM HOW TO GET SLING */
QueryBuilder qbuilder = sling.getService(QueryBuilder.class);
String fulltextSearchTerm = "Geometrixx";
// create query description as hash map (simplest way, same as form
// post)
Map<String, String> map = new HashMap<String, String>();
// create query description as hash map (simplest way, same as form
// post)
map.put("path", "/content");
map.put("type", "cq:Page");
map.put("group.p.or", "true"); // combine this group with OR
map.put("group.1_fulltext", fulltextSearchTerm);
map.put("group.1_fulltext.relPath", "jcr:content");
map.put("group.2_fulltext", fulltextSearchTerm);
map.put("group.2_fulltext.relPath", "jcr:content/@cq:tags");
// can be done in map or with Query methods
map.put("p.offset", "0"); // same as query.setStart(0) below
map.put("p.limit", "20"); // same as query.setHitsPerPage(20) below
Query query = qbuilder.createQuery(PredicateGroup.create(map), session);
query.setStart(0);
query.setHitsPerPage(20);
SearchResult result = query.getResult();