info.magnolia.cms.taglibs.util
Class SimpleSearchTag

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by info.magnolia.cms.taglibs.util.SimpleSearchTag
All Implemented Interfaces:
Serializable, javax.servlet.jsp.tagext.IterationTag, javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.Tag

public class SimpleSearchTag
extends javax.servlet.jsp.tagext.TagSupport

A simple tag which allows searching in all the site content with a "natural language" query. It simply strips all the reserved chars from input string, build an xpath query and feed Magnolia QueryManager. By defaults search terms are ANDed, but it also supports using the AND or OR keywords in the query string. Search is not case sensitive and it's performed on any non-binary property. A collection on Content (page) objects is added to the specified scope with the specified name.

Version:
$Revision: 41137 $ ($Author: gjoseph $)
Author:
Fabrizio Giustina
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
SimpleSearchTag()
           
 
Method Summary
 int doStartTag()
           
protected  String generateComplexXPathQuery()
          Deprecated. as from 3.5.5, this query is deemed to complex and not properly working, since it forces a search on non-indexed word. The better generateSimpleQuery() method is recommended.
protected  String generateSimpleQuery(String input)
          This generates a simple jcr:contains query.
protected  String generateXPathQuery()
          Deprecated. as from 3.5.5, this query is deemed to complex and not properly working, since it forces a search on non-indexed word. The better generateSimpleQuery() method is recommened.
 String getItemType()
           
 String getRepository()
           
 String getStartPath()
           
 boolean isSupportSubstringSearch()
           
 void release()
           
 void setItemType(String itemType)
          The itemTypes search/returned by this tag.
 void setQuery(String query)
          Query to execute (e.g.
 void setRepository(String repository)
          The repository we search in.
 void setScope(String scope)
          Scope for the variable.
 void setStartLevel(int startLevel)
          The start level for search, defaults to 0.
 void setStartPath(String startPath)
          The path we search in.
 void setSupportSubstringSearch(boolean supportSubstringSearch)
          Deprecated. not used when useSimpleJcrQuery is set to true.
 void setUseSimpleJcrQuery(boolean useSimpleJcrQuery)
          Set this attribute to false to generate the search query as it was generated until Magnolia 3.5.4 (which will force a search on non-indexed word, which usually leads in less good results).
 void setVar(String var)
          The search results (a collection of Content nodes (pages)) will be added to the pagecontext using this name.
protected  String startPath()
           
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
doAfterBody, doEndTag, findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleSearchTag

public SimpleSearchTag()
Method Detail

setQuery

public void setQuery(String query)
Query to execute (e.g. "magnolia AND cms OR info")


setVar

public void setVar(String var)
The search results (a collection of Content nodes (pages)) will be added to the pagecontext using this name.


setScope

public void setScope(String scope)
Scope for the variable. Can be "page" (default), "request", "session", "application".


setStartLevel

public void setStartLevel(int startLevel)
The start level for search, defaults to 0. Can be used to limit the search only to the current website tree.


doStartTag

public int doStartTag()
               throws javax.servlet.jsp.JspException
Specified by:
doStartTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doStartTag in class javax.servlet.jsp.tagext.TagSupport
Throws:
javax.servlet.jsp.JspException

generateSimpleQuery

protected String generateSimpleQuery(String input)
This generates a simple jcr:contains query.

See Also:
"6.6.5.2 jcr:contains Function" from the JCR Spec (pages 110-111) for details.

startPath

protected String startPath()

generateComplexXPathQuery

protected String generateComplexXPathQuery()
Deprecated. as from 3.5.5, this query is deemed to complex and not properly working, since it forces a search on non-indexed word. The better generateSimpleQuery() method is recommended.


generateXPathQuery

protected String generateXPathQuery()
Deprecated. as from 3.5.5, this query is deemed to complex and not properly working, since it forces a search on non-indexed word. The better generateSimpleQuery() method is recommened.

Split search terms and build an xpath query in the form: //*[@jcr:primaryType='mgnl:content']/\*\/\*[jcr:contains(., 'first') or jcr:contains(., 'second')].

Returns:
valid xpath expression or null if the given query doesn't contain at least one valid search term

release

public void release()
Specified by:
release in interface javax.servlet.jsp.tagext.Tag
Overrides:
release in class javax.servlet.jsp.tagext.TagSupport
See Also:
TagSupport.release()

getRepository

public String getRepository()

setRepository

public void setRepository(String repository)
The repository we search in. Default is website repository.


isSupportSubstringSearch

public boolean isSupportSubstringSearch()

setSupportSubstringSearch

public void setSupportSubstringSearch(boolean supportSubstringSearch)
Deprecated. not used when useSimpleJcrQuery is set to true.

Search for substrings too. This can decrease performance. Default value is false.


setUseSimpleJcrQuery

public void setUseSimpleJcrQuery(boolean useSimpleJcrQuery)
Set this attribute to false to generate the search query as it was generated until Magnolia 3.5.4 (which will force a search on non-indexed word, which usually leads in less good results). As from 3.5.5, this is true by default, and generates simpler and better queries. See "6.6.5.2 jcr:contains Function" from the JCR Spec (pages 110-111) for details.


getItemType

public String getItemType()
Returns:
the itemType

setItemType

public void setItemType(String itemType)
The itemTypes search/returned by this tag. Default is mgnl:content which is used for pages.


getStartPath

public String getStartPath()

setStartPath

public void setStartPath(String startPath)
The path we search in.



Copyright © 2003-2011 Magnolia International Ltd.. All Rights Reserved.