title: CQ5 Java QueryBuilder API
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>The example code is as below:</p>
  
  <pre><code>        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&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  
          // 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();
  </code></pre>