[
http://jira.magnolia-cms.com/browse/MAGNOLIA-2293?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=23633#action_23633
]
Will Scheidegger commented on MAGNOLIA-2293:
--------------------------------------------
Well, I just found out that the code above only works once properly if you use
the tag with a startLevel attribute. If the tag has no "startPath" set, but
does have a "startLevel" the path is calculated from the active page and then
stored in the "startPath". Since from then on the tag does have a value in
"startPath" the path is never calculated again. So if you use the tag in
different contexts (e.g. in two differen language branches) after its first use
it will always search in that branch. Using a temporary path for the query
solves the problem.
{code}
protected String generateSimpleQuery(String input) {
String queryStartPath = ""; // temporary start path used only for this
query
// search only in a specific subtree
if (StringUtils.isBlank(this.startPath) && this.startLevel > 0) {
try {
Content activePage = Resource.getActivePage();
if (activePage != null) {
queryStartPath =
StringUtils.strip(activePage.getAncestor(this.startLevel).getHandle(), "/");
//$NON-NLS-1$
}
}
catch (RepositoryException e) {
log.error(e.getMessage(), e);
}
} else if (StringUtils.isNotBlank(this.startPath)) {
queryStartPath = this.startPath;
}
// jcr and xpath escaping :
final String escapedQuery = input.replaceAll("'", "\\\\''");
return queryStartPath +
"//*...@jcr:primaryType='mgnl:content']//*[jcr:contains(., '"+ escapedQuery
+"')]";
}
{code}
> 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: Grégory Joseph
> Priority: Minor
> Fix For: 4.1.1
>
> 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]>
----------------------------------------------------------------