how do search component customization in cq5.6? | Community
Skip to main content
October 16, 2015
Solved

how do search component customization in cq5.6?

  • October 16, 2015
  • 1 reply
  • 971 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Ojjis

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-manager.topic.html/forum__mqzl-i_need_to_developa.html

Good luck
Johan

1 reply

Ojjis
OjjisAccepted solution
Level 7
October 16, 2015

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-manager.topic.html/forum__mqzl-i_need_to_developa.html

Good luck
Johan