org.alfresco.web.bean.search
Class SearchContext

java.lang.Object
  extended by org.alfresco.web.bean.search.SearchContext
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AVMBrowseBean.FormSearchContext

public class SearchContext
extends java.lang.Object
implements java.io.Serializable

Holds the context required to build a search query and can return the populated query.

Builds a lucene format search string from each of the supplied attributes and terms. Can be serialized to and from XML format for saving and restoring of previous searches.

See Also:
Serialized Form

Field Summary
static int SEARCH_ALL
          Search mode constants
static int SEARCH_FILE_NAMES
           
static int SEARCH_FILE_NAMES_CONTENTS
           
static int SEARCH_SPACE_NAMES
           
protected  java.util.List simpleSearchAdditionalAttrs
          any extra simple query attributes to add to the search
 
Constructor Summary
SearchContext()
           
 
Method Summary
 void addAttributeQuery(org.alfresco.service.namespace.QName qname, java.lang.String value)
          Add an additional attribute to search against
 void addFixedValueQuery(org.alfresco.service.namespace.QName qname, java.lang.String value)
          Add an additional fixed value attribute to search against
 void addRangeQuery(org.alfresco.service.namespace.QName qname, java.lang.String lower, java.lang.String upper, boolean inclusive)
          Add an additional range attribute to search against
 void addSimpleAttributeQuery(org.alfresco.service.namespace.QName qname)
          Add an additional attribute to search against for simple searches
 java.lang.String buildQuery(int minimum)
          Build the search query string based on the current search context members.
 SearchContext fromXML(java.lang.String xml)
          Restore a SearchContext from an XML definition
 java.lang.String getAttributeQuery(org.alfresco.service.namespace.QName qname)
           
 java.lang.String[] getCategories()
           
 java.lang.String getContentType()
           
 java.lang.String getFixedValueQuery(org.alfresco.service.namespace.QName qname)
           
 java.lang.String getFolderType()
           
 boolean getForceAndTerms()
           
 java.lang.String getLocation()
           
 java.lang.String getMimeType()
           
 int getMode()
           
static java.lang.String getPathFromSpaceRef(org.alfresco.service.cmr.repository.NodeRef ref, boolean children)
          Generate a search XPATH pointing to the specified node, optionally return an XPATH that includes the child nodes.
 org.alfresco.web.bean.search.SearchContext.RangeProperties getRangeProperty(org.alfresco.service.namespace.QName qname)
           
 java.lang.String getText()
           
 void setCategories(java.lang.String[] categories)
           
 void setContentType(java.lang.String contentType)
           
 void setFolderType(java.lang.String folderType)
           
 void setForceAndTerms(boolean forceAndTerms)
           
 void setLocation(java.lang.String location)
           
 void setMimeType(java.lang.String mimeType)
           
 void setMode(int mode)
           
 void setSimpleSearchAdditionalAttributes(java.util.List attrs)
          Sets the additional attribute to search against for simple searches.
 void setText(java.lang.String text)
           
 java.lang.String toXML()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEARCH_ALL

public static final int SEARCH_ALL
Search mode constants

See Also:
Constant Field Values

SEARCH_FILE_NAMES_CONTENTS

public static final int SEARCH_FILE_NAMES_CONTENTS
See Also:
Constant Field Values

SEARCH_FILE_NAMES

public static final int SEARCH_FILE_NAMES
See Also:
Constant Field Values

SEARCH_SPACE_NAMES

public static final int SEARCH_SPACE_NAMES
See Also:
Constant Field Values

simpleSearchAdditionalAttrs

protected java.util.List simpleSearchAdditionalAttrs
any extra simple query attributes to add to the search

Constructor Detail

SearchContext

public SearchContext()
Method Detail

buildQuery

public java.lang.String buildQuery(int minimum)
Build the search query string based on the current search context members.

Parameters:
minimum - small possible textual string used for a match this does not effect fixed values searches (e.g. boolean, int values) or date ranges
Returns:
prepared search query string

getPathFromSpaceRef

public static java.lang.String getPathFromSpaceRef(org.alfresco.service.cmr.repository.NodeRef ref,
                                                   boolean children)
Generate a search XPATH pointing to the specified node, optionally return an XPATH that includes the child nodes.

Parameters:
id - Of the node to generate path too
children - Whether to include children of the node
Returns:
the path

getCategories

public java.lang.String[] getCategories()
Returns:
Returns the categories to use for the search

setCategories

public void setCategories(java.lang.String[] categories)
Parameters:
categories - The categories to set as a list of search XPATHs

getLocation

public java.lang.String getLocation()
Returns:
Returns the node XPath to search in or null for all.

setLocation

public void setLocation(java.lang.String location)
Parameters:
location - The node XPATH to search from or null for all..

getMode

public int getMode()
Returns:
Returns the mode to use during the search (see constants)

setMode

public void setMode(int mode)
Parameters:
mode - The mode to use during the search (see constants)

getText

public java.lang.String getText()
Returns:
Returns the search text string.

setText

public void setText(java.lang.String text)
Parameters:
text - The search text string.

getContentType

public java.lang.String getContentType()
Returns:
Returns the contentType.

setContentType

public void setContentType(java.lang.String contentType)
Parameters:
contentType - The content type to restrict attribute search against.

getFolderType

public java.lang.String getFolderType()
Returns:
Returns the folderType.

setFolderType

public void setFolderType(java.lang.String folderType)
Parameters:
folderType - The folder type to restrict attribute search against.

getMimeType

public java.lang.String getMimeType()
Returns:
Returns the mimeType.

setMimeType

public void setMimeType(java.lang.String mimeType)
Parameters:
mimeType - The mimeType to set.

addSimpleAttributeQuery

public void addSimpleAttributeQuery(org.alfresco.service.namespace.QName qname)
Add an additional attribute to search against for simple searches

Parameters:
qname - QName of the attribute to search against
value - Value of the attribute to use

setSimpleSearchAdditionalAttributes

public void setSimpleSearchAdditionalAttributes(java.util.List attrs)
Sets the additional attribute to search against for simple searches.

Parameters:
attrs - The list of attributes to search against

addAttributeQuery

public void addAttributeQuery(org.alfresco.service.namespace.QName qname,
                              java.lang.String value)
Add an additional attribute to search against

Parameters:
qname - QName of the attribute to search against
value - Value of the attribute to use

getAttributeQuery

public java.lang.String getAttributeQuery(org.alfresco.service.namespace.QName qname)

addRangeQuery

public void addRangeQuery(org.alfresco.service.namespace.QName qname,
                          java.lang.String lower,
                          java.lang.String upper,
                          boolean inclusive)
Add an additional range attribute to search against

Parameters:
qname - QName of the attribute to search against
lower - Lower value for range
upper - Upper value for range
inclusive - True for inclusive within the range, false otherwise

getRangeProperty

public org.alfresco.web.bean.search.SearchContext.RangeProperties getRangeProperty(org.alfresco.service.namespace.QName qname)

addFixedValueQuery

public void addFixedValueQuery(org.alfresco.service.namespace.QName qname,
                               java.lang.String value)
Add an additional fixed value attribute to search against

Parameters:
qname - QName of the attribute to search against
value - Fixed value of the attribute to use

getFixedValueQuery

public java.lang.String getFixedValueQuery(org.alfresco.service.namespace.QName qname)

getForceAndTerms

public boolean getForceAndTerms()
Returns:
Returns if AND is forced between text terms. False (OR terms) is the default.

setForceAndTerms

public void setForceAndTerms(boolean forceAndTerms)
Parameters:
forceAndTerms - Set true to force AND between text terms. Otherwise OR is the default.

toXML

public java.lang.String toXML()
Returns:
this SearchContext as XML Example: CDATA int XPath XPath String String String String String String boolean String CDATA

fromXML

public SearchContext fromXML(java.lang.String xml)
Restore a SearchContext from an XML definition

Parameters:
xml - XML format SearchContext @see #toXML()


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.