[ 
http://jira.magnolia-cms.com/browse/MAGNOLIA-2293?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=22137#action_22137
 ] 

Will Scheidegger commented on MAGNOLIA-2293:
--------------------------------------------

The proposed fix would overwrite any startPath attribute. Therefore I would 
suggest to do it like this: 
\\ 

{code} 
    protected String generateSimpleQuery(String input) { 
        // search only in a specific subtree 
        if (StringUtils.isBlank(this.startPath)) { 
            if (this.startLevel > 0) { 
                try { 
                    Content activePage = Resource.getActivePage(); 
                    if (activePage != null) { 
                        this.startPath = 
StringUtils.strip(activePage.getAncestor(this.startLevel).getHandle(), "/"); 
//$NON-NLS-1$ 
                    } 
                } catch (RepositoryException e) { 
                    log.error(e.getMessage(), e); 
                } 
            } else { 
                this.startPath = ""; 
            } 
        } else { 
            this.startPath = StringUtils.strip(this.startPath, "/"); 
//$NON-NLS-1$ 
        } 

        // jcr and xpath escaping : 
        final String escapedQuery = input.replaceAll("'", "\\\\''"); 
        String queryString = this.startPath + 
"//*...@jcr:primaryType='mgnl:content']//*[jcr:contains(., '" + escapedQuery + 
"')]"; 
        log.debug("query string: " + queryString); 
        return queryString; 
    } 
{code} 

I tried to put create a patch file with this fix (see attached 
SimpleSearchTagPatch.diff), but since I let my IDE format the code, I got tons 
of diffs. I removed the unnecessary stuff manually and hope the patch file 
still works.

> startLevel of simpleSearch is ignored
> -------------------------------------
>
>                 Key: MAGNOLIA-2293
>                 URL: http://jira.magnolia-cms.com/browse/MAGNOLIA-2293
>             Project: Magnolia
>          Issue Type: Bug
>          Components: taglibs
>    Affects Versions: 3.6, 3.6.1, 3.6.3, 4.0.1
>         Environment: Windows Vista Business SP1
> jdk1.6.0_07
> apache-tomcat-5.5.26
> magnolia-bundled-webapp-3.6.1
>            Reporter: Oliver Knorr
>            Assignee: Fabrizio Giustina
>            Priority: Minor
>         Attachments: SimpleSearchTagPatch.diff
>
>
> 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:
> # 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.
> # 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" />
> # 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
> {code}
>     protected String generateSimpleQuery(String input) {
>         // jcr and xpath escaping :
>         final String escapedQuery = input.replace("'", "\\''");
>         return "//*...@jcr:primaryType='mgnl:content']//*[jcr:contains(., '"+ 
> escapedQuery +"')]";
>     }
> {code}
> with the following (taking the code from generateXPathQuery()):
> {code}
>     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 +"')]";
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.magnolia-cms.com/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to