|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencms.search.CmsSearchParameters
public class CmsSearchParameters
Contains the search parameters for a call to
.CmsSearchIndex.search(org.opencms.file.CmsObject, CmsSearchParameters)
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.
Nested Class Summary | |
---|---|
class |
CmsSearchParameters.CmsSearchFieldQuery
Describes a specific search field query. |
Field Summary | |
---|---|
protected int |
m_displayPages
The number of displayed pages returned by getPageLinks(). |
protected int |
m_matchesPerPage
The number of matches per page. |
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<java.lang.String> fields,
java.util.List<java.lang.String> roots,
java.util.List<java.lang.String> categories,
java.util.List<java.lang.String> resourceTypes,
boolean calculateCategories,
org.apache.lucene.search.Sort sort)
Creates a new search parameter instance with the provided parameter values. |
Method Summary | |
---|---|
void |
addFieldQuery(CmsSearchParameters.CmsSearchFieldQuery query)
Adds an individual query for a search field. |
void |
addFieldQuery(java.lang.String fieldName,
java.lang.String searchQuery,
org.apache.lucene.search.BooleanClause.Occur occur)
Adds an individual query for a search field. |
boolean |
getCalculateCategories()
Returns whether category counts are calculated for search results or not. |
java.util.List<java.lang.String> |
getCategories()
Returns the list of categories to limit the search to. |
int |
getDisplayPages()
Returns the maximum number of pages which should be shown. |
java.util.List<CmsSearchParameters.CmsSearchFieldQuery> |
getFieldQueries()
Returns the list of individual field queries. |
java.util.List<java.lang.String> |
getFields()
Returns the list of search index field names (Strings) to search in. |
java.lang.String |
getIndex()
Get the name of the index for the search. |
int |
getMatchesPerPage()
Gets the number of matches displayed on each page. |
long |
getMaxDateCreated()
Returns the creation date the resources have to have as maximum. |
long |
getMaxDateLastModified()
Returns the last modification date the resources have to have as maximum. |
long |
getMinDateCreated()
Returns the creation date the resources have to have as minimum. |
long |
getMinDateLastModified()
Returns the last modification date the resources have to have as minimum. |
java.lang.String |
getQuery()
Returns the search query to use. |
int |
getQueryLength()
Gets the minimum search query length. |
java.util.List<java.lang.String> |
getResourceTypes()
Returns the list of resource types to limit the search to. |
java.util.List<java.lang.String> |
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. |
CmsSearchIndex |
getSearchIndex()
Returns the search index to search in or null if not set before ( ). |
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. |
boolean |
isExcerptOnlySearchedFields()
Returns true if fields configured for the excerpt should be used for generating the excerpt only
if they have been actually searched in. |
CmsSearchParameters |
restrict(CmsSearchParameters restriction)
Creates a merged parameter set from this parameters, restricted by the given other parameters. |
void |
setCalculateCategories(boolean flag)
Set whether category counts shall be calculated for the corresponding search results or not. |
void |
setCategories(java.util.List<java.lang.String> categories)
Set the list of categories (strings) to this parameters. |
void |
setDisplayPages(int value)
Sets the maximum number of pages which should be shown. |
void |
setExcerptOnlySearchedFields(boolean excerptAllFields)
Controls if the excerpt from a field is generated only for searched fields, or for all fields (the default). |
void |
setFields(java.util.List<java.lang.String> 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 |
setMatchesPerPage(int matches)
Sets the number of matches per page. |
void |
setMaxDateCreated(long dateCreatedTo)
Sets the creation date the resources have to have as maximum. |
void |
setMaxDateLastModified(long dateLastModifiedTo)
Sets the last modification date the resources have to have as maximum. |
void |
setMinDateCreated(long dateCreatedFrom)
Sets the creation date the resources have to have as minimum. |
void |
setMinDateLastModified(long dateLastModifiedFrom)
Sets the last modification date the resources have to have as minimum. |
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 |
setResourceTypes(java.util.List<java.lang.String> resourceTypes)
Set the list of resource types (strings) to limit the search to. |
void |
setRoots(java.util.List<java.lang.String> 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 |
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 according to
the given sort name. |
java.lang.String |
toQueryString()
Creates a query String build from this search parameters for HTML links. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final org.apache.lucene.search.Sort SORT_DATE_CREATED
public static final org.apache.lucene.search.Sort SORT_DATE_LASTMODIFIED
public static final org.apache.lucene.search.Sort SORT_DEFAULT
null
gave best performance).
public static final java.lang.String[] SORT_NAMES
public static final org.apache.lucene.search.Sort SORT_TITLE
protected int m_displayPages
protected int m_matchesPerPage
Constructor Detail |
---|
public CmsSearchParameters()
Before using this search parameters for a search method
has to be invoked. setQuery(String)
public CmsSearchParameters(java.lang.String query)
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 category counts are calculated for the result. Sorting is turned off. This is a simple but fast setup.
query
- the query to search forpublic CmsSearchParameters(java.lang.String query, java.util.List<java.lang.String> fields, java.util.List<java.lang.String> roots, java.util.List<java.lang.String> categories, java.util.List<java.lang.String> resourceTypes, boolean calculateCategories, org.apache.lucene.search.Sort sort)
query
- the search term to search the indexfields
- the list of fields to searchroots
- only resource that are sub-resource of one of the search roots are included in the search resultcategories
- the list of categories to limit the search toresourceTypes
- the list of resource types to limit the search tocalculateCategories
- 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 searchMethod Detail |
---|
public void addFieldQuery(CmsSearchParameters.CmsSearchFieldQuery query)
If this is used, any setting made with setQuery(String)
and setFields(List)
will be ignored and only the individual field search settings will be used.
query
- the query to addpublic void addFieldQuery(java.lang.String fieldName, java.lang.String searchQuery, org.apache.lucene.search.BooleanClause.Occur occur)
If this is used, any setting made with setQuery(String)
and setFields(List)
will be ignored and only the individual field search settings will be used.
fieldName
- the field namesearchQuery
- the search queryoccur
- the occur parameter for the query in the fieldpublic boolean getCalculateCategories()
public java.util.List<java.lang.String> getCategories()
public int getDisplayPages()
public java.util.List<CmsSearchParameters.CmsSearchFieldQuery> getFieldQueries()
public java.util.List<java.lang.String> getFields()
public java.lang.String getIndex()
public int getMatchesPerPage()
public long getMaxDateCreated()
public long getMaxDateLastModified()
public long getMinDateCreated()
public long getMinDateLastModified()
public java.lang.String getQuery()
public int getQueryLength()
public java.util.List<java.lang.String> getResourceTypes()
public java.util.List<java.lang.String> getRoots()
Only resource that are sub-resource of one of the search roots are included in the search result.
public java.lang.String getSearchCategories()
public CmsSearchIndex getSearchIndex()
setSearchIndex(CmsSearchIndex)
).
setSearchIndex(CmsSearchIndex)
)public int getSearchPage()
public java.lang.String getSearchRoots()
This method is a "sibling" to method
but with
the support of being usable with widget technology. getRoots()
setSortName(String)
public org.apache.lucene.search.Sort getSort()
public java.lang.String getSortName()
SORT_NAMES
,
setSortName(String)
public boolean isCalculateCategories()
true
if the category count is calculated for all search results.
true
if the category count is calculated for all search resultspublic boolean isExcerptOnlySearchedFields()
true
if fields configured for the excerpt should be used for generating the excerpt only
if they have been actually searched in.
The default setting is false
, which means all text fields configured for the excerpt will
be used to generate the excerpt, regardless if they have been searched in or not.
Please note: A field will only be included in the excerpt if it has been configured as excerpt="true"
in opencms-search.xml
. This method controls if so configured fields are used depending on the
fields searched, see setFields(List)
.
true
if fields configured for the excerpt should be used for generating the excerpt only
if they have been actually searched inpublic CmsSearchParameters restrict(CmsSearchParameters restriction)
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()
and
getRoots()
are intersected with the lists of this search parameters. Only
elements contained in both lists are included for the created search parameters.
If a list in either the restriction or in this search parameters is getCategories()
null
,
the list from the other search parameters is used directly.
The values for
and isCalculateCategories()
of this parameters are used for the restricted parameters.getSort()
restriction
- the parameters to restrict this parameters with
public void setCalculateCategories(boolean flag)
flag
- true if category counts shall be calculated for the corresponding search results or false if notpublic void setCategories(java.util.List<java.lang.String> categories)
categories
- the list of categories (strings) of this parameterspublic void setDisplayPages(int value)
Enter an odd value to achieve a nice, "symmetric" output.
value
- the maximum number of pages which should be shownpublic void setExcerptOnlySearchedFields(boolean excerptAllFields)
excerptAllFields
- if true
, the excerpt is generated only from the fields actually searched inisExcerptOnlySearchedFields()
public void setFields(java.util.List<java.lang.String> fields)
fields
- the list of strings of names of fields to search in to setpublic void setIndex(java.lang.String indexName)
indexName
- the name of the indexpublic void setMatchesPerPage(int matches)
matches
- the number of matches per pagepublic void setMaxDateCreated(long dateCreatedTo)
dateCreatedTo
- the creation date the resources have to have as maximum to setpublic void setMaxDateLastModified(long dateLastModifiedTo)
dateLastModifiedTo
- the last modification date the resources have to have as maximum to setpublic void setMinDateCreated(long dateCreatedFrom)
dateCreatedFrom
- the creation date the resources have to have as minimum to setpublic void setMinDateLastModified(long dateLastModifiedFrom)
dateLastModifiedFrom
- the the last modification date the resources have to have as minimum to setpublic void setQuery(java.lang.String query)
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 front ends that don't encode manually as characters like sole "%" (without number suffix) will cause an Exception.
query
- the query to search for to setpublic void setQueryLength(int length)
length
- the minimum search query lengthpublic void setResourceTypes(java.util.List<java.lang.String> resourceTypes)
resourceTypes
- the list of resource types (strings) to limit the search topublic void setRoots(java.util.List<java.lang.String> roots)
roots
- the list of strings of roots to search under for the search to setpublic void setSearchCategories(java.lang.String categories)
categories
- the comma separated category names to restrict search topublic void setSearchIndex(CmsSearchIndex index) throws CmsIllegalArgumentException
index
- the search index to use for the search to set.
CmsIllegalArgumentException
- if null is given as argumentpublic void setSearchPage(int page)
page
- the search page to displaypublic void setSearchRoots(java.lang.String rootNameList)
rootNameList
- the comma separated search root names to restrict search topublic void setSort(org.apache.lucene.search.Sort sortOrder)
sortOrder
- the instance that defines the sort order for search results to setpublic void setSortName(java.lang.String sortName)
Sort
according to
the given sort name.
For a list of valid sort names, please see
.SORT_NAMES
sortName
- the name of the sort to useSORT_NAMES
public java.lang.String toQueryString()
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |