Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Search

Avatar

Level 2

i want to brings all the pages that contains special character and without special character in the same query

this is my query , how can i do that ?

 

public SearchResult generalSearch(Map mapQuerySearch) {
try {
startTiming();
Map<String, String> map = new HashMap<>();
map = mapQuerySearch;
Query query = builder.createQuery(PredicateGroup.create(map), session);
SearchResult result = query.getResult();
endTiming(map);
return result;
} catch (Exception e) {
log.error("QueryBsn - General search error",e);
}
return null;
}


thank you

6 Replies

Avatar

Level 5

Hi @naoufal_afa ,

 

Could you please provide me the map , what your passing in  generalSearch method.

 

Thanks,

Sandeep.

Avatar

Level 2

Hello  this all the value i pass in the map 

String keyword = searchFilter.getKeyword(); Map<String, String> map = new HashMap<>(); if(searchFilter.getContentType() == null || searchFilter.getContentType().size() == 0) { //We are not searching resources map.put("type", "cq:PageContent"); } List searchPaths = searchFilter.getPaths(); if (searchPaths.size() <= 1) { map.put("path", searchPaths.get(0)); } else { for (int i = 0; i < searchPaths.size(); i++) { map.put("group." + (i + 1) + "_path", searchPaths.get(i)); } } if (searchFilter.getResourceTypeList() != null && searchFilter.getResourceTypeList().size() > 0) { map.put("1_property", "@sling:resourceType"); //Add all resource types to find if (searchFilter.getResourceTypeList() != null) { for (int i = 0; i < searchFilter.getResourceTypeList().size(); i++) { int groupIndex = 1 + i; map.put("1_property."+groupIndex+"_value", searchFilter.getResourceTypeList().get(i)); } } //Hide In Search is missing map.put("3_property", "@hideInSearch"); map.put("3_property.value", "true"); map.put("3_property.operation", "not"); } else { if(searchFilter.getContentType() != null && searchFilter.getContentType().size() > 0) { map.put("1_property", "fileReference"); setContentTypeFilter(map, "1_property", searchFilter.getContentType(), "like"); } } map.put("group.p.or", "true"); if (searchFilter.getTypologies() != null && searchFilter.getTypologies().size() > 0) { if(!searchFilter.getType().equals("all")){ for (String typology : searchFilter.getTypologies()) { groupIndex++; map.put("group."+groupIndex+"_property", "@"+QueryConstants.typology); map.put("group."+groupIndex+"_property.value", QueryConstants.NAMESPACE_TYPOLOGY+":"+typology); } } } if (StringUtils.isNotBlank(keyword)) { //Common for all articles map.put("fulltext", keyword); } map.put("orderby", "@customDate"); map.put("orderby.sort", orderBy); map.put("p.offset", "0"); map.put("p.limit",limit);

Avatar

Level 2

Hello , this is the map where i pass all the values

String keyword = searchFilter.getKeyword();
Boolean all = searchFilter != null && StringUtils.isNotBlank(searchFilter.getType()) && searchFilter.getType().equals("all");
Boolean documentsSearch = searchFilter != null && StringUtils.isNotBlank(searchFilter.getType()) && searchFilter.getType().equals(QueryConstants.documentsSearch);
Boolean hasCategories = searchFilter.getCategories() != null && searchFilter.getCategories().size() > 0;
Boolean hasSections = searchFilter.getSections() != null && searchFilter.getSections().size() > 0;
Boolean hasResourceTypeList = searchFilter.getResourceTypeList() != null && searchFilter.getResourceTypeList().size() > 0;
Boolean hasContentTypeList = searchFilter.getContentType() != null && searchFilter.getContentType().size() > 0;
Boolean hasRegions = searchFilter.getRegions() != null && searchFilter.getRegions().size() > 0;
Boolean hasBrands = searchFilter.getBrands() != null && searchFilter.getBrands().size() > 0;
Boolean hasAlbums = searchFilter.getAlbums() != null && searchFilter.getAlbums().size() > 0;
Boolean hasHighlights = searchFilter.getHighlights() != null && searchFilter.getHighlights().size() > 0;
Boolean hasDateFilter = searchFilter.getDateStart() != null || searchFilter.getDateEnd() != null;
//String dateStrFormatted = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(new Date());

//*** GROUP 0 - GENERAL GROUP - IF WE ARE SEARCHING FOR ALL WE WILL CREATE GP1 AND GP2, IN DOCUMENTS PAGE GP1, IN OTHER SPECIFIC CASE GP2 ***//
Map<String, String> map = new HashMap<>();
if (all) {
map.put("0_group.p.or", "true");
}
if (all || documentsSearch) {
map.put("0_group.1_group.type", "dam:AssetContent");
}
if (all || !documentsSearch) {
map.put("0_group.2_group.type", "cq:PageContent");
}

 

//Hide In Search is missing
map.put("0_group.2_group.2_group.3_property", "@hideInSearch");
map.put("0_group.2_group.2_group.3_property.value", "true");
map.put("0_group.2_group.2_group.3_property.operation", "not");

int groupIndex = 3;

//***COMMON GROUP - GROUP ASSET AND GROUP PAGECONTENT USE CATEGORIES AND CUSTOMDATE***//
// Date Range
if (hasDateFilter) {
map.put("1_group.daterange.property", "@customDate");
if (searchFilter.getDateStart() != null) {
map.put("1_group.daterange.lowerBound", EnelCommonUtils.formatDate(searchFilter.getDateStart().getTime(), "yyyy-MM-dd", null));
map.put("1_group.daterange.lowerOperation", ">=");
}
if (searchFilter.getDateEnd() != null) {
map.put("1_group.daterange.upperBound", EnelCommonUtils.formatDate(searchFilter.getDateEnd().getTime(), "yyyy-MM-dd", null));
}
}

 

map.put("orderby", "@customDate");
map.put("orderby.sort", orderBy);

map.put("p.offset", "0");
map.put("p.limit",limit);

Avatar

Level 2
String keyword = searchFilter.getKeyword(); Boolean all = searchFilter != null && StringUtils.isNotBlank(searchFilter.getType()) && searchFilter.getType().equals("all");Boolean documentsSearch = searchFilter != null && StringUtils.isNotBlank(searchFilter.getType()) && searchFilter.getType().equals(QueryConstants.documentsSearch); Boolean hasCategories = searchFilter.getCategories() != null && searchFilter.getCategories().size() > 0;Boolean hasSections = searchFilter.getSections() != null && searchFilter.getSections().size() > 0;Boolean hasResourceTypeList = searchFilter.getResourceTypeList() != null && searchFilter.getResourceTypeList().size() > 0;Boolean hasContentTypeList = searchFilter.getContentType() != null && searchFilter.getContentType().size() > 0;Boolean hasRegions = searchFilter.getRegions() != null && searchFilter.getRegions().size() > 0;Boolean hasBrands = searchFilter.getBrands() != null && searchFilter.getBrands().size() > 0;Boolean hasAlbums = searchFilter.getAlbums() != null && searchFilter.getAlbums().size() > 0;Boolean hasHighlights = searchFilter.getHighlights() != null && searchFilter.getHighlights().size() > 0;Boolean hasDateFilter = searchFilter.getDateStart() != null || searchFilter.getDateEnd() != null;//String dateStrFormatted = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(new Date());map.put("0_group.2_group.2_group.3_property", "@hideInSearch"); map.put("0_group.2_group.2_group.3_property.value", "true"); map.put("0_group.2_group.2_group.3_property.operation", "not"); int groupIndex = 3; map.put("orderby", "@customDate"); map.put("orderby.sort", orderBy); map.put("p.offset", "0");map.put("p.limit",limit); if (StringUtils.isNotBlank(keyword)) { map.put("fulltext", keyword); }

Avatar

Community Advisor

Do you want all the pages in same results(page with special char & page without special char).

Create 2 sets - One with all page and another with special character. Get difference of two sets to get pages without special character



Arun Patidar