startLevel of simpleSearch is ignored
-------------------------------------
Key: MAGNOLIA-2293
URL: http://jira.magnolia.info/browse/MAGNOLIA-2293
Project: Magnolia
Issue Type: Bug
Components: taglibs
Affects Versions: 3.6.1, 3.6
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
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 "//[EMAIL
PROTECTED]: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+"//[EMAIL
PROTECTED]: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.info/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
----------------------------------------------------------------
for list details see
http://documentation.magnolia.info/
----------------------------------------------------------------