4 Replies Latest reply on Apr 9, 2013 6:09 AM by balaji_pydi

    How do I make simplesearch look for the same tag in multiple locations

    crestenst Level 1

      Currently i'm trying to write a simplesearch implementation that will only return the result it if contains a specific tag. I would also like to include DAM assets in the search, wherein lies the problem:

       

      I need to look in both jcr:content and jcr:content/metadata for the tag, and if the tag is found in either location, return that page. Here is the code I am trying to use, but it currently only looks for the tag(s) in one location. Any tips on how to get it to look in multiple locations?

      Code:

       

       

       

                          tagPredicate = new Predicate("tags2", "tagid");

                          tagPredicate.set("property", "jcr:content/cq:tags");

                          for (Cookie cookie : tagsFromCookie) {

                                         if (cookie.getName().contains(CREDENTIALS)) {

                                                        tagPredicate.set("tagid",

                                                                            (cookie.getValue().replaceAll("---", ":")));

                                                        search.addPredicate(tagPredicate);

                                         }

                          }

       

      Thanks for any help you can give!

        • 1. Re: How do I make simplesearch look for the same tag in multiple locations
          crestenst Level 1

          I figured this one out on my own. Kind of a "Doh!" moment.

           

          What I ended up doing is this: I created a PredicateGroup, and populated this group with the predicates I needed. Then, I set the PredicateGroup allRequired to false. Voila! It works!

           

          Code:

           

                    PredicateGroup tagPredicateGroup = new PredicateGroup();

                              tagPredicateGroup.setAllRequired(false);

           

                              Predicate tagPredicate = new Predicate("tags", "tagid");

                              if (slingRequest.getParameter(GROUP1) != null) {

           

                                             tagPredicate = new Predicate("tags", "tagid");

                                             tagPredicate.set("property", "jcr:content/cq:tags");

                                             tagPredicate.set("tagid", GROUP1);

                                             tagPredicateGroup.add(tagPredicate);

           

                                             tagPredicate = new Predicate("damTags", "tagid");

                                             tagPredicate.set("property", "jcr:content/metadata/cq:tags");

                                             tagPredicate.set("tagid", GROUP1);

                                             tagPredicateGroup.add(tagPredicate);

           

                              }

           

                              return tagPredicateGroup;

          • 2. Re: How do I make simplesearch look for the same tag in multiple locations
            balaji_pydi Level 1

            Hi, if you see this line of code

            search.addPredicate(tagPredicate);

              from which api, you got this search object, because, in the api com.day.cq.wcm.foundation.Search, this method search.addPredicate is not present, then tried to use SimpleSearchImpl which is present in the api com.day.cq.search.impl.SimpleSearchImpl, however when I tried to use that import, it is throwing error, saying that the import is invalid,please let me know in which api this addPredicate method is present.

            • 3. Re: How do I make simplesearch look for the same tag in multiple locations
              crestenst Level 1

              You're going to import the non-impl SimpleSearch. Then, you're going to adapt a ResourceResolver to the SimpleSearch class.

               

              http://dev.day.com/docs/en/cq/5-5/javadoc/com/day/cq/search/SimpleSearch.html


              You're never going to want to grab the impl.

              • 4. Re: How do I make simplesearch look for the same tag in multiple locations
                balaji_pydi Level 1

                Ya correct, I need to use resourceResolver, thanks for helping me.