2015-04-18 2 views
2

Теперь сталкиваемся с проблемой в Querybuilder api при попытке с несколькими путями с несколькими свойствами. Код прилагается здесь, что я сделал. Он отлично работает одним путем с несколькими свойствами и несколькими путями с одним свойством. Мое требование как множественный путь с несколькими свойствами, а также некоторые предикатыAEM CQ5 Query builder Несколько путей с несколькими свойствами Проблема

предложение будет оценили

Map<String, String> map = new HashMap<String, String>(); 
     ArrayList<Predicate> group = new ArrayList<Predicate>(); 
     JSONArray jsonArray = new JSONArray(); 

     if (null != searchPathList && searchPathList.size() > 0) { 
      mapCount = searchPathList.size(); 
      for (int i = 0; i < searchPathList.size(); i++) { 
       //map.put("group." + (i + 1) + "_path", searchPathList.get(i)); 
      } 
     } 
     // group.add(new Predicate("mypath1").set("path", "/content/opinion/columns")); 
     // group.add(new Predicate("mypath2").set("path", "/content/opinion/books")); 
     map.put("group.1_path","/content/opinion/columns"); 
     map.put("group.2_path","/content/opinion/books"); 
     map.put("type", CQJCRConstants.JCRPRIMARYTYPEPAGE); 
     //combine this group with OR 
     map.put("group.p.or", "true"); 
     map.put("p.offset", "0"); 
     map.put("p.hits", "full"); 

     if (!TheCommonUtility.isEmpty(searchKeyWord)) { 



      /* map.put("group." + (mapCount + 1) + "_fulltext", searchKeyWord); 
      map.put("group." + (mapCount + 1) + "_fulltext.relPath", "jcr:content/@jcr:title"); 
      map.put("group." + (mapCount + 2) + "_fulltext", searchKeyWord); 
      map.put("group." + (mapCount + 2) + "_fulltext.relPath", "jcr:content/@jcr:description"); 
      map.put("group." + (mapCount + 3) + "_fulltext", searchKeyWord); 
      map.put("group." + (mapCount + 3) + "_fulltext.relPath", "jcr:content/@cq:tags"); 
      map.put("group." + (mapCount + 4) + "_fulltext", searchKeyWord); 
      map.put("group." + (mapCount + 4) + "_fulltext.relPath", "jcr:content/@authorName"); 
      map.put("group." + (mapCount + 5) + "_fulltext", searchKeyWord); 

      map.put("group." + (mapCount + 5) + "_fulltext.relPath", "jcr:content/@SlugName"); 
      PredicateGroup searchpathgroup = new PredicateGroup("path"); 

      searchpathgroup.setAllRequired(false); 

      searchpathgroup.add(new Predicate("mypath1").set("path", "/content/opinion/columns")); 
      searchpathgroup.add(new Predicate("mypath2").set("path", "/content/opinion/books"));  
      */ 

      PredicateGroup searchKeyWordgroup = new PredicateGroup("property"); 
      searchKeyWordgroup.setAllRequired(false); 

      Predicate titleskPredicate = new Predicate("title"); 
      titleskPredicate.set(JcrPropertyPredicateEvaluator.OPERATION, JcrPropertyPredicateEvaluator.OP_LIKE); 
      titleskPredicate.set("property", "fn:lower-case(@" + "jcr:content/jcr:title"); 
      titleskPredicate.set("value", "%" + searchKeyWord.toLowerCase() + "%"); 
      searchKeyWordgroup.add(titleskPredicate); 

      Predicate desskPredicate = new Predicate("description"); 
      desskPredicate.set(JcrPropertyPredicateEvaluator.OPERATION, JcrPropertyPredicateEvaluator.OP_LIKE); 
      desskPredicate.set("property", "fn:lower-case(@" + "jcr:content/jcr:description"); 
      desskPredicate.set("value", "%" + searchKeyWord.toLowerCase() + "%"); 
      searchKeyWordgroup.add(desskPredicate); 

      Predicate tagskPredicate = new Predicate("tagssk"); 
      tagskPredicate.set(JcrPropertyPredicateEvaluator.OPERATION, JcrPropertyPredicateEvaluator.OP_LIKE); 
      tagskPredicate.set("property", "fn:lower-case(@" + "jcr:content/cq:tags"); 
      tagskPredicate.set("value", "%" + searchKeyWord.toLowerCase() + "%"); 
      searchKeyWordgroup.add(tagskPredicate); 

      Predicate authorNameskPredicate = new Predicate("authorNameSk"); 
      authorNameskPredicate.set(JcrPropertyPredicateEvaluator.OPERATION, JcrPropertyPredicateEvaluator.OP_LIKE); 
      authorNameskPredicate.set("property", "fn:lower-case(@" + JcrConstants.JCR_CONTENT + "/" + "authorName" 
       + ")"); 
      authorNameskPredicate.set("value", "%" + searchKeyWord.toLowerCase() + "%"); 
      searchKeyWordgroup.add(authorNameskPredicate); 

      Predicate slugskPredicate = new Predicate("SlugName"); 
      slugskPredicate.set(JcrPropertyPredicateEvaluator.OPERATION, JcrPropertyPredicateEvaluator.OP_LIKE); 
      slugskPredicate.set("property", "fn:lower-case(@" + "jcr:content/SlugName"); 
      slugskPredicate.set("value", "%" + searchKeyWord.toLowerCase() + "%"); 
      searchKeyWordgroup.add(slugskPredicate); 

      group.add(searchKeyWordgroup); 

     } 

     Predicate notPredicate = new Predicate("hideInNav", "property"); 
     notPredicate.set(JcrPropertyPredicateEvaluator.OPERATION, JcrPropertyPredicateEvaluator.OP_NOT); 
     notPredicate.set("property", JcrConstants.JCR_CONTENT + "/" + "hideInNav"); 
     notPredicate.set("value", "true"); 
     group.add(notPredicate); 

     Predicate notMasterTitlePredicate = new Predicate("pageMasterNot", "property"); 
     notMasterTitlePredicate.set(JcrPropertyPredicateEvaluator.OPERATION, JcrPropertyPredicateEvaluator.OP_UNEQUALS); 
     notMasterTitlePredicate.set("property", JcrConstants.JCR_CONTENT + "/" + JcrConstants.JCR_TITLE); 
     notMasterTitlePredicate.set("value", "Master Article"); 
     group.add(notMasterTitlePredicate); 

     if (!ThecommonUtility.isEmpty(author)) { 
      Predicate authorNamePredicate = new Predicate("authorName", "property"); 
      authorNamePredicate.set(JcrPropertyPredicateEvaluator.OPERATION, JcrPropertyPredicateEvaluator.OP_LIKE); 
      authorNamePredicate 
       .set("property", "fn:lower-case(@" + JcrConstants.JCR_CONTENT + "/" + "authorName" + ")"); 
      authorNamePredicate.set("value", "%" + author.toLowerCase() + "%"); 
      group.add(authorNamePredicate); 
     } 
     if (!ThecommonUtility.isEmpty(tagId)) { 
      Predicate tagPredecate = new Predicate("tags", "tagid"); 
      tagPredecate.set(JcrPropertyPredicateEvaluator.OPERATION, JcrPropertyPredicateEvaluator.OP_LIKE); 
      tagPredecate.set(JcrPropertyPredicateEvaluator.PROPERTY, JcrConstants.JCR_CONTENT + "/" + "cq:tags"); 
      tagPredecate.set("1_" + JcrPropertyPredicateEvaluator.VALUE, tagId); 
      group.add(tagPredecate); 
     } 

     if (!ThecommonUtility.isEmpty(start_time) && !ThecommonUtility.isEmpty(end_time)) { 
      final Predicate createdDatePredicate = new Predicate("issueDate", "daterange"); 
      createdDatePredicate.set("property", JcrConstants.JCR_CONTENT + "/" + CQJCRConstants.ISSUEDATE); 
      createdDatePredicate.set("lowerBound", start_time); 
      createdDatePredicate.set("lowerOperation", ">="); 
      createdDatePredicate.set("upperBound", end_time); 
      createdDatePredicate.set("upperOperation", "<="); 
      group.add(createdDatePredicate); 
     } 

     if (!ThecommonUtility.isEmpty(order_by) && order_by.equalsIgnoreCase("cq:lastModified")) { 
      final Predicate orderByPredicate = new Predicate("orderBy", Predicate.ORDER_BY); 
      orderByPredicate.set(Predicate.ORDER_BY, "@" + JcrConstants.JCR_CONTENT + "/" + order_by); 
      orderByPredicate.set("orderby.index", "true"); 
      orderByPredicate.set(Predicate.PARAM_SORT, Predicate.SORT_DESCENDING); 
      group.add(orderByPredicate); 
     } else if (!ThecommonUtility.isEmpty(order_by) && order_by.equalsIgnoreCase("oldest")) { 
      final Predicate orderByPredicate = new Predicate("orderBy", Predicate.ORDER_BY); 
      orderByPredicate.set(Predicate.ORDER_BY, "@" + JcrConstants.JCR_CONTENT + "/" + order_by); 
      orderByPredicate.set("orderby.index", "true"); 
      orderByPredicate.set(Predicate.PARAM_SORT, Predicate.SORT_ASCENDING); 
      group.add(orderByPredicate); 
     } 
     try { 
      session = request.getResourceResolver().adaptTo(Session.class); 
      Query query = qbuilder.createQuery(PredicateGroup.create(map), session); 
      for (Predicate p : group) { 
       query.getPredicates().add(p); 
      }   
      query.setExcerpt(true); 
      query.setStart(startHit); 
      query.setHitsPerPage(showMoreCount); 
      result = query.getResult(); 

ответ

1

Решение: map.put («group.p.or», «правда»); поместите этот код в начало и используйте концепцию PredicateGroup для пути поиска {group=group: or=true[ {3_fulltext=fulltext: relPath=jcr:content/@jcr:title, fulltext=bibi} {4_fulltext=fulltext: relPath=jcr:content/@jcr:description, fulltext=bibi} {5_fulltext=fulltext: relPath=jcr:content/@cq:tags, fulltext=bibi} {6_fulltext=fulltext: relPath=jcr:content/@authorName, fulltext=bibi} {7_fulltext=fulltext: relPath=jcr:content/@weekSlugName, fulltext=bibi} ]} {type=type: type=cq:Page} {path=group: or=true[ {1_mypath1=mypath1: path=/content/week/opinion/columns} {2_mypath2=mypath2: path=/content/week/opinion/books} ]} {hideInNav=property: operation=not, value=true, property=jcr:content/hideInNav} {pageMasterNot=property: operation=unequals, value=Master Article, property=jcr:content/jcr:title} {authorName=property: operation=like, value=%ajish%, property=fn:lower-case(@jcr:content/authorName)} {orderBy=orderby: orderby.index=true, sort=desc, [email protected]:content/cq:lastModified}

Смежные вопросы