Now am facing issue in Querybuilder api while trying with Multiple Path with Multiple Properties. Code is attached here what I did. It is working fine one path with multiple properties and multiple path with one property. My requirement is like multiple path with multiple properties and also some predicates
suggestion would be appreciated
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();