Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-2293

startLevel of simpleSearch is ignored

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 4.1.2, 4.2.2
    • 3.6, 3.6.1, 3.6.3, 4.0.1, 4.2.1
    • taglibs
    • None
    • Windows Vista Business SP1
      jdk1.6.0_07
      apache-tomcat-5.5.26
      magnolia-bundled-webapp-3.6.1

      The startLevel attribute of cmsu:simplesearch should limit the search only to the current website tree, but is ignored at least in Magnolia 3.6 and 3.6.1.

      Steps to reproduce:

      1. Open the demo search page http://localhost:8080/magnoliaAuthor/help/search.html and search for "mail". 5 results from inside and outside the help tree should appear.
      2. In webapps\magnoliaAuthor\templates\samples\templates\sample-search.jsp, replace the line
        <cmsu:simpleSearch query="${param.query}" var="results" />
        with the line
        <cmsu:simpleSearch query="${param.query}" var="results" startLevel="1" />
      3. Try the search again. Expected result: one hit (/magnoliaAuthor/help/user-mailing-list.html),
        actual result: all the 5 results from the first test are shown.

      The reason seems to be info\magnolia\cms\taglibs\util\SimpleSearchTag.java: the startLevel is respected only in the obsolete generateXPathQuery() method, but not in the new generateSimpleQuery().

      I could fix the problem for me, by replacing

          protected String generateSimpleQuery(String input) {
              // jcr and xpath escaping :
              final String escapedQuery = input.replace("'", "\\''");
              return "//*[@jcr:primaryType='mgnl:content']//*[jcr:contains(., '"+ escapedQuery +"')]";
          }
      

      with the following (taking the code from generateXPathQuery()):

          protected String generateSimpleQuery(String input) {
              // search only in a specific subtree
              startPath = "";
              if (this.startLevel != 0) {
                  try {
                      Content activePage = Resource.getActivePage();
                      if (activePage != null) {
                          startPath = StringUtils.strip(activePage.getAncestor(this.startLevel).getHandle(), "/"); //$NON-NLS-1$
                      }
                  }
                  catch (RepositoryException e) {
                      log.error(e.getMessage(), e);
                  }
              }
      
              // jcr and xpath escaping :
              final String escapedQuery = input.replace("'", "\\''");
              return startPath+"//*[@jcr:primaryType='mgnl:content']//*[jcr:contains(., '"+ escapedQuery +"')]";
          }
      

        Acceptance criteria

              had Jan Haderka
              damiel Oliver Knorr
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Bug DoR
                  Task DoD