org.opencms.search
Class CmsSearchParameters

java.lang.Object
  extended byorg.opencms.search.CmsSearchParameters

public class CmsSearchParameters
extends java.lang.Object

Contains the search parameters for a call to CmsSearchIndex.search(org.opencms.file.CmsObject, CmsSearchParameters, int).

Primary purpose is translation of search arguments to response parameters and from request parameters as well as support for creation of restrictions of several search query parameter sets.

Since:
6.0.0
Version:
$Revision: 1.8 $, $Revision: 1.8 $
Author:
Alexander Kandzior

Field Summary
protected  CmsSearchIndex m_index
          The index to search.
protected  int m_page
          The current result page.
protected  int m_queryLength
          The minimum length of the search query.
static org.apache.lucene.search.Sort SORT_DATE_CREATED
          Sort result documents by date of creation, then score.
static org.apache.lucene.search.Sort SORT_DATE_LASTMODIFIED
          Sort result documents by date of last modification, then score.
static org.apache.lucene.search.Sort SORT_DEFAULT
          Default sort order (by document score - for this null gave best performance).
static java.lang.String[] SORT_NAMES
          Names of the default sort options.
static org.apache.lucene.search.Sort SORT_TITLE
          Sort result documents by title, then score.
 
Constructor Summary
CmsSearchParameters()
          Creates a new search parameter instance with no search query and default values for the remaining parameters.
CmsSearchParameters(java.lang.String query)
          Creates a new search parameter instance with the provided search query and default values for the remaining parameters.
CmsSearchParameters(java.lang.String query, java.util.List fields, java.util.List roots, java.util.List categories, boolean calculateCategories, org.apache.lucene.search.Sort sort)
          Creates a new search parameter instance with the provided parameter values.
 
Method Summary
 boolean getCalculateCategories()
          Returns wether category counts are calculated for search results or not.
 java.util.List getCategories()
          Returns the list of categories to limit the search to.
 java.util.List getFields()
          Returns the list of search index fields to search in.
 java.lang.String getIndex()
          Get the name of the index for the search.
 java.lang.String getQuery()
          Returns the search query to use.
 int getQueryLength()
          Gets the minimum search query length.
 java.util.List getRoots()
          Returns the list of strings of search roots to use.
 java.lang.String getSearchCategories()
          Returns the list of categories to limit the search to.
 boolean getSearchFieldContent()
          Returns wether the content field will be searched or not.
 boolean getSearchFieldDescription()
          Returns wether the description field will be searched or not.
 boolean getSearchFieldKeywords()
          Returns wether the keywords field will be searched or not.
 boolean getSearchFieldMeta()
          Returns wether the meta field will be searched or not.
 boolean getSearchFieldTitle()
          Returns wether the title field will be searched or not.
 CmsSearchIndex getSearchIndex()
          Returns the search index to search in or null if not set before (setSearchIndex(CmsSearchIndex)).
 int getSearchPage()
          Returns the search page to display.
 java.lang.String getSearchRoots()
          Returns the comma separated lists of root folder names to restrict search to.
 org.apache.lucene.search.Sort getSort()
          Returns the instance that defines the sort order for the results.
 java.lang.String getSortName()
          Returns the name of the sort option being used.
 boolean isCalculateCategories()
          Returns true if the category count is calculated for all search results.
 CmsSearchParameters restrict(CmsSearchParameters restriction)
          Creates a merged parameter set from this parameters, restricted by the given other parameters.
 void setCalculateCategories(boolean flag)
          Set wether category counts shall be calculated for the corresponding search results or not.
 void setCategories(java.util.List categories)
          Set the list of categories (strings) to this parameters.
 void setFields(java.util.List fields)
          Sets the list of strings of names of fields to search in.
 void setIndex(java.lang.String indexName)
          Set the name of the index to search.
 void setQuery(java.lang.String query)
          Sets the query to search for.
 void setQueryLength(int length)
          Sets the minimum length of the search query.
 void setRoots(java.util.List roots)
          Sets the list of strings of roots to search under for the search.
 void setSearchCategories(java.lang.String categories)
          Set the comma separated search root names to restrict search to.
 void setSearchFieldContent(boolean flag)
          Set wether the content field should be searched.
 void setSearchFieldDescription(boolean flag)
          Set wether the description field should be searched.
 void setSearchFieldKeywords(boolean flag)
          Set wether the title field should be searched.
 void setSearchFieldMeta(boolean flag)
          Set wether the meta field should be searched.
 void setSearchFieldTitle(boolean flag)
          Set wether the title field should be searched.
 void setSearchIndex(CmsSearchIndex index)
          Sets the search index to use for the search.
 void setSearchPage(int page)
          Set the search page to display.
 void setSearchRoots(java.lang.String rootNameList)
          Set the comma separated search root names to restrict search to.
 void setSort(org.apache.lucene.search.Sort sortOrder)
          Set the instance that defines the sort order for search results.
 void setSortName(java.lang.String sortName)
          Sets the internal member of type Sort according to the given sort name.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SORT_DATE_CREATED

public static final org.apache.lucene.search.Sort SORT_DATE_CREATED
Sort result documents by date of creation, then score.


SORT_DATE_LASTMODIFIED

public static final org.apache.lucene.search.Sort SORT_DATE_LASTMODIFIED
Sort result documents by date of last modification, then score.


SORT_DEFAULT

public static final org.apache.lucene.search.Sort SORT_DEFAULT
Default sort order (by document score - for this null gave best performance).


SORT_NAMES

public static final java.lang.String[] SORT_NAMES
Names of the default sort options.


SORT_TITLE

public static final org.apache.lucene.search.Sort SORT_TITLE
Sort result documents by title, then score.


m_index

protected CmsSearchIndex m_index
The index to search.


m_page

protected int m_page
The current result page.


m_queryLength

protected int m_queryLength
The minimum length of the search query.

Constructor Detail

CmsSearchParameters

public CmsSearchParameters()
Creates a new search parameter instance with no search query and default values for the remaining parameters.

Before using this search parameters for a search method setQuery(String) has to be invoked.


CmsSearchParameters

public CmsSearchParameters(java.lang.String query)
Creates a new search parameter instance with the provided search query and default values for the remaining parameters.

Only the "meta" field (combination of content and title) will be used for search. No search root restriction is chosen. No category restriction is used. No categorie counts are calculated for the result. Sorting is turned off. This is a simple but fast setup.

Parameters:
query - the query to search for

CmsSearchParameters

public CmsSearchParameters(java.lang.String query,
                           java.util.List fields,
                           java.util.List roots,
                           java.util.List categories,
                           boolean calculateCategories,
                           org.apache.lucene.search.Sort sort)
Creates a new search parameter instance with the provided parameter values.

Parameters:
query - the search term to search the index
fields - the list of fields to search
roots - only resource that are sub-resource of one of the search roots are included in the search result
categories - the list of categories to limit the search to
calculateCategories - if true, the category count is calculated for all search results (use with caution, this option uses much performance)
sort - the sort order for the search
Method Detail

getCalculateCategories

public boolean getCalculateCategories()
Returns wether category counts are calculated for search results or not.

Returns:
a boolean that tells wether category counts are calculated for search results or not

getCategories

public java.util.List getCategories()
Returns the list of categories to limit the search to.

Returns:
the list of categories to limit the search to

getFields

public java.util.List getFields()
Returns the list of search index fields to search in.

Returns:
the list of search index fields to search in

getIndex

public java.lang.String getIndex()
Get the name of the index for the search.

Returns:
the name of the index for the search

getQuery

public java.lang.String getQuery()
Returns the search query to use.

Returns:
the search query to use

getQueryLength

public int getQueryLength()
Gets the minimum search query length.

Returns:
the minimum search query length

getRoots

public java.util.List getRoots()
Returns the list of strings of search roots to use.

Only resource that are sub-resource of one of the search roots are included in the search result.

Returns:
the list of strings of search roots to use

getSearchCategories

public java.lang.String getSearchCategories()
Returns the list of categories to limit the search to.

Returns:
the list of categories to limit the search to

getSearchFieldContent

public boolean getSearchFieldContent()
Returns wether the content field will be searched or not.

Returns:
wether the content field will be searched or not
See Also:
I_CmsDocumentFactory.DOC_CONTENT

getSearchFieldDescription

public boolean getSearchFieldDescription()
Returns wether the description field will be searched or not.

Returns:
wether the description field will be searched or not
See Also:
I_CmsDocumentFactory.DOC_DESCRIPTION

getSearchFieldKeywords

public boolean getSearchFieldKeywords()
Returns wether the keywords field will be searched or not.

Returns:
wether the keywords field will be searched or not
See Also:
I_CmsDocumentFactory.DOC_KEYWORDS

getSearchFieldMeta

public boolean getSearchFieldMeta()
Returns wether the meta field will be searched or not.

Returns:
wether the meta field will be searched or not
See Also:
I_CmsDocumentFactory.DOC_META

getSearchFieldTitle

public boolean getSearchFieldTitle()
Returns wether the title field will be searched or not.

Returns:
wether the title field will be searched or not
See Also:
I_CmsDocumentFactory.DOC_TITLE_INDEXED

getSearchIndex

public CmsSearchIndex getSearchIndex()
Returns the search index to search in or null if not set before (setSearchIndex(CmsSearchIndex)).

Returns:
the search index to search in or null if not set before (setSearchIndex(CmsSearchIndex))

getSearchPage

public int getSearchPage()
Returns the search page to display.

Returns:
the search page to display

getSearchRoots

public java.lang.String getSearchRoots()
Returns the comma separated lists of root folder names to restrict search to.

This method is a "sibling" to method getRoots() but with the support of being useable with widget technology.

Returns:
the comma separated lists of field names to search in
See Also:
setSortName(String)

getSort

public org.apache.lucene.search.Sort getSort()
Returns the instance that defines the sort order for the results.

Returns:
the instance that defines the sort order for the results

getSortName

public java.lang.String getSortName()
Returns the name of the sort option being used.

Returns:
the name of the sort option being used
See Also:
SORT_NAMES, setSortName(String)

isCalculateCategories

public boolean isCalculateCategories()
Returns true if the category count is calculated for all search results.

Returns:
true if the category count is calculated for all search results

restrict

public CmsSearchParameters restrict(CmsSearchParameters restriction)
Creates a merged parameter set from this parameters, restricted by the given other parameters.

This is mainly intended for "search in search result" functions.

The restricted query is build of the queries of both parameters, appended with AND.

The lists in the restriction for getFields(), getRoots() and getCategories() are intersected with the lists of this search parameters. Only elements containd in both lists are included for the created search parameters. If a list in either the restriction or in this search parameters is null, the list from the other search parameters is used direclty.

The values for isCalculateCategories() and getSort() of this parameters are used for the restricted parameters.

Parameters:
restriction - the parameters to restrict this parameters with
Returns:
the restricted parameters

setCalculateCategories

public void setCalculateCategories(boolean flag)
Set wether category counts shall be calculated for the corresponding search results or not.

Parameters:
flag - true if category counts shall be calculated for the corresponding search results or false if not

setCategories

public void setCategories(java.util.List categories)
Set the list of categories (strings) to this parameters.

Parameters:
categories - the list of categories (strings) of this parameters

setFields

public void setFields(java.util.List fields)
Sets the list of strings of names of fields to search in.

Parameters:
fields - the list of strings of names of fields to search in to set

setIndex

public void setIndex(java.lang.String indexName)
Set the name of the index to search.

Parameters:
indexName - the name of the index

setQuery

public void setQuery(java.lang.String query)
Sets the query to search for.

The decoding here is tailored for query strings that are additionally manually utf-8 encoded at client side (javascript) to get around an issue with special chars in applications that use non- utf-8 encoding (e.g. ISO-8859-1) OpenCms applications. It is not recommended to use this with frontends that don't encode manually as characters like sole "%" (without number suffix) will cause an Exception.

Parameters:
query - the querye to search for to set

setQueryLength

public void setQueryLength(int length)
Sets the minimum length of the search query.

Parameters:
length - the minimum search query length

setRoots

public void setRoots(java.util.List roots)
Sets the list of strings of roots to search under for the search.

Parameters:
roots - the list of strings of roots to search under for the search to set

setSearchCategories

public void setSearchCategories(java.lang.String categories)
Set the comma separated search root names to restrict search to.

Parameters:
categories - the comma separated category names to restrict search to

setSearchFieldContent

public void setSearchFieldContent(boolean flag)
Set wether the content field should be searched.

This method is a widget support for CmsCheckboxWidget.

Parameters:
flag - true if the field I_CmsDocumentFactory.DOC_CONTENT shall be searched - false else

setSearchFieldDescription

public void setSearchFieldDescription(boolean flag)
Set wether the description field should be searched.

This method is a widget support for CmsCheckboxWidget.

Parameters:
flag - true if the field I_CmsDocumentFactory.DOC_DESCRIPTION shall be searched - false else

setSearchFieldKeywords

public void setSearchFieldKeywords(boolean flag)
Set wether the title field should be searched.

This method is a widget support for CmsCheckboxWidget.

Parameters:
flag - true if the field I_CmsDocumentFactory.DOC_KEYWORDS shall be searched - false else

setSearchFieldMeta

public void setSearchFieldMeta(boolean flag)
Set wether the meta field should be searched.

This method is a widget support for CmsCheckboxWidget.

Parameters:
flag - true if the field I_CmsDocumentFactory.DOC_META shall be searched - false else

setSearchFieldTitle

public void setSearchFieldTitle(boolean flag)
Set wether the title field should be searched.

This method is a widget support for CmsCheckboxWidget.

Parameters:
flag - true if the field I_CmsDocumentFactory.DOC_TITLE_INDEXED shall be searched - false else

setSearchIndex

public void setSearchIndex(CmsSearchIndex index)
                    throws CmsIllegalArgumentException
Sets the search index to use for the search.

Parameters:
index - the search index to use for the search to set.
Throws:
CmsIllegalArgumentException - if null is given as argument

setSearchPage

public void setSearchPage(int page)
Set the search page to display.

Parameters:
page - the search page to display

setSearchRoots

public void setSearchRoots(java.lang.String rootNameList)
Set the comma separated search root names to restrict search to.

Parameters:
rootNameList - the comma separated search root names to restrict search to

setSort

public void setSort(org.apache.lucene.search.Sort sortOrder)
Set the instance that defines the sort order for search results.

Parameters:
sortOrder - the instance that defines the sort order for search results to set

setSortName

public void setSortName(java.lang.String sortName)
Sets the internal member of type Sort according to the given sort name.

For a list of valid sort names, please see SORT_NAMES.

Parameters:
sortName - the name of the sort to use
See Also:
SORT_NAMES

toString

public java.lang.String toString()
See Also:
Object.toString()