3 Replies Latest reply on May 22, 2013 11:30 PM by ddigal

    regarding query builder api

    ddigal
      private QueryBuilder builder;

          public static void search() {
              String fulltextSearchTerm = "Geometrixx";
             
              // create query description as hash map (simplest way, same as form post)
              Map<String, String> map = new HashMap<String, String>();
              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 = builder.createQuery(PredicateGroup.create(map), session);
             
              //query.setStart(0);
              //query.setHitsPerPage(20);

              SearchResult result = query.getResult();
             
              // paging metadata
              int hitsPerPage = result.getHits().size(); // 20 (set above) or lower
              long totalMatches = result.getTotalMatches();
              long offset = result.getStartIndex();
              long numberOfPages = totalMatches / 20;
             
              // iterating over the results
              for (Hit hit : result.getHits()) {
                  String path = hit.getPath();
                  ValueMap props = hit.getProperties();
                  // ...
              }

              // extracting facets
              Map<String, Facet> facets = result.getFacets();
              for (String key : facets.keySet()) {
                  Facet facet = facets.get(key);
                  if (facet.getContainsHit()) {
                      for (Bucket bucket : facet.getBuckets()) {
                          String value = bucket.getValue();
                          long count = bucket.getCount();
                          // ...
                          // retrieving the predicate that is required to query for this bucket
                          Map<String, String> params = bucket.getPredicate().getParameters();
                          for (String k : params.keySet()) {
                              // ...
                          }
                      }
                  }
              }
          }


      //  why the above code is not working can anybody tell me the reason .why it is not working"Query query = builder.createQuery(PredicateGroup.create(map), session);"

      is there any specific parameters for createQuery ();