Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

how do search component customization in cq5.6?

Avatar

Former Community Member

Need to ristrict the search only for the page name.Seach result should not show any content inside the page which matches search.

Please let me know how to achive this. 

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hello, i was writing a post about how to do you own search servlet before..
What you can do is to make use of the com.day.cq.search.QueryBuilder api to create you own custom query.

This example will restrict the search only to page names and descriptions..
of course you can remove one of these to only have the title

HashMap<String, String> map = new HashMap<String, String>();
        map.put("path", "YOUR SEARCH PATH");
        map.put("type", "cq:Page");
        map.put("group.p.or", "true"); // combine this group with OR
        map.put("group.1_fulltext", "*" + SEARCHTERM + "*");
        map.put("group.1_fulltext.relPath", "@jcr:content/jcr:description");
        map.put("group.2_fulltext", "*" + SEARCHTERM + "*");
        map.put("group.2_fulltext.relPath", "@jrc:content/jcr:title");
        map.put("orderby","SOME PROPERTY);
        map.put("p.limit", "PAGINATEAFTER"); 


        QueryBuilder builder = request.getResourceResolver().adaptTo(QueryBuilder.class);
        Session session = request.getResourceResolver().adaptTo(Session.class);
        Query query = builder.createQuery(PredicateGroup.create(map), session);
 

       query.setStart(STARTVALUE);

       Get the result ====>   SearchResult result = query.getResult();
       Get the list of hits =====> List<Hits> hits= result.getHits();

Then thats quite much everything there is..
If you are unsure how to build your queries   http://localhost:4502/libs/cq/search/content/querydebug.html   is a great resource to try your queries
and the Query Builder help page is more than great for all the remaining questions :)   http://dev.day.com/docs/en/cq/current/dam/customizing_and_extendingcq5dam/query_builder.html

See my other post about this here:

http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

Good luck
Johan

View solution in original post

1 Reply

Avatar

Correct answer by
Level 7

Hello, i was writing a post about how to do you own search servlet before..
What you can do is to make use of the com.day.cq.search.QueryBuilder api to create you own custom query.

This example will restrict the search only to page names and descriptions..
of course you can remove one of these to only have the title

HashMap<String, String> map = new HashMap<String, String>();
        map.put("path", "YOUR SEARCH PATH");
        map.put("type", "cq:Page");
        map.put("group.p.or", "true"); // combine this group with OR
        map.put("group.1_fulltext", "*" + SEARCHTERM + "*");
        map.put("group.1_fulltext.relPath", "@jcr:content/jcr:description");
        map.put("group.2_fulltext", "*" + SEARCHTERM + "*");
        map.put("group.2_fulltext.relPath", "@jrc:content/jcr:title");
        map.put("orderby","SOME PROPERTY);
        map.put("p.limit", "PAGINATEAFTER"); 


        QueryBuilder builder = request.getResourceResolver().adaptTo(QueryBuilder.class);
        Session session = request.getResourceResolver().adaptTo(Session.class);
        Query query = builder.createQuery(PredicateGroup.create(map), session);
 

       query.setStart(STARTVALUE);

       Get the result ====>   SearchResult result = query.getResult();
       Get the list of hits =====> List<Hits> hits= result.getHits();

Then thats quite much everything there is..
If you are unsure how to build your queries   http://localhost:4502/libs/cq/search/content/querydebug.html   is a great resource to try your queries
and the Query Builder help page is more than great for all the remaining questions :)   http://dev.day.com/docs/en/cq/current/dam/customizing_and_extendingcq5dam/query_builder.html

See my other post about this here:

http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

Good luck
Johan