cmssearchparameters.java
来自「找了很久才找到到源代码」· Java 代码 · 共 938 行 · 第 1/3 页
JAVA
938 行
public long getMinDateLastModified() {
return m_minDateLastModified;
}
/**
* Returns the search query to use.<p>
*
* @return the search query to use
*/
public String getQuery() {
return m_query;
}
/**
* Gets the minimum search query length.<p>
*
* @return the minimum search query length
*/
public int getQueryLength() {
return m_queryLength;
}
/**
* Returns the list of strings of search roots to use.<p>
*
* Only resource that are sub-resource of one of the search roots are included in the search result.<p>
*
* @return the list of strings of search roots to use
*/
public List getRoots() {
return m_roots;
}
/**
* Returns the list of categories to limit the search to.<p>
*
* @return the list of categories to limit the search to
*/
public String getSearchCategories() {
return toSeparatedString(getCategories(), ',');
}
/**
* Returns the search index to search in or null if not set before
* (<code>{@link #setSearchIndex(CmsSearchIndex)}</code>). <p>
*
* @return the search index to search in or null if not set before (<code>{@link #setSearchIndex(CmsSearchIndex)}</code>)
*/
public CmsSearchIndex getSearchIndex() {
return m_index;
}
/**
* Returns the search page to display.<p>
*
* @return the search page to display
*/
public int getSearchPage() {
return m_page;
}
/**
* Returns the comma separated lists of root folder names to restrict search to.<p>
*
* This method is a "sibling" to method <code>{@link #getRoots()}</code> but with
* the support of being useable with widget technology. <p>
*
* @return the comma separated lists of field names to search in
*
* @see #setSortName(String)
*/
public String getSearchRoots() {
return toSeparatedString(m_roots, ',');
}
/**
* Returns the instance that defines the sort order for the results.
*
* @return the instance that defines the sort order for the results
*/
public Sort getSort() {
return m_sort;
}
/**
* Returns the name of the sort option being used.<p>
* @return the name of the sort option being used
*
* @see #SORT_NAMES
* @see #setSortName(String)
*/
public String getSortName() {
if (m_sort == SORT_DATE_CREATED) {
return SORT_NAMES[1];
}
if (m_sort == SORT_DATE_LASTMODIFIED) {
return SORT_NAMES[2];
}
if (m_sort == SORT_TITLE) {
return SORT_NAMES[3];
}
return SORT_NAMES[0];
}
/**
* Returns <code>true</code> if the category count is calculated for all search results.<p>
*
* @return <code>true</code> if the category count is calculated for all search results
*/
public boolean isCalculateCategories() {
return m_calculateCategories;
}
/**
* Returns <code>true</code> if fields configured for the excerpt should be used for generating the excerpt only
* if they have been actually searched in.<p>
*
* The default setting is <code>false</code>, which means all text fields configured for the excerpt will
* be used to gernerate the excerpt, regardless if they have been searched in or not.<p>
*
* Please note: A field will only be included in the excerpt if it has been configured as <code>excerpt="true"</code>
* in <code>opencms-search.xml</code>. This method controls if so configured fields are used depending on the
* fields searched, see {@link #setFields(List)}.<p>
*
* @return <code>true</code> if fields configured for the excerpt should be used for generating the excerpt only
* if they have been actually searched in
*/
public boolean isExcerptOnlySearchedFields() {
return m_excerptOnlySearchedFields;
}
/**
* Creates a merged parameter set from this parameters, restricted by the given other parameters.<p>
*
* This is mainly intended for "search in search result" functions.<p>
*
* The restricted query is build of the queries of both parameters, appended with AND.<p>
*
* The lists in the restriction for <code>{@link #getFields()}</code>, <code>{@link #getRoots()}</code> and
* <code>{@link #getCategories()}</code> are <b>intersected</b> 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 <code>null</code>,
* the list from the other search parameters is used direclty.<p>
*
* The values for
* <code>{@link #isCalculateCategories()}</code>
* and <code>{@link #getSort()}</code> of this parameters are used for the restricted parameters.<p>
*
* @param restriction the parameters to restrict this parameters with
* @return the restricted parameters
*/
public CmsSearchParameters restrict(CmsSearchParameters restriction) {
// append queries
StringBuffer query = new StringBuffer(256);
if (getQuery() != null) {
// don't blow up unneccessary closures (if CmsSearch is reused and restricted several times)
boolean closure = !getQuery().startsWith("+(");
if (closure) {
query.append("+(");
}
query.append(getQuery());
if (closure) {
query.append(")");
}
}
if (restriction.getQuery() != null) {
// don't let lucene max terms be exceeded in case someone reuses a CmsSearch and continuously restricts
// query with the same restrictions...
if (query.indexOf(restriction.getQuery()) < 0) {
query.append(" +(");
query.append(restriction.getQuery());
query.append(")");
}
}
// restrict fields
List fields = null;
if ((m_fields != null) && (m_fields.size() > 0)) {
if ((restriction.getFields() != null) && (restriction.getFields().size() > 0)) {
fields = ListUtils.intersection(m_fields, restriction.getFields());
} else {
fields = m_fields;
}
} else {
fields = restriction.getFields();
}
// restrict roots
List roots = null;
if ((m_roots != null) && (m_roots.size() > 0)) {
if ((restriction.getRoots() != null) && (restriction.getRoots().size() > 0)) {
roots = ListUtils.intersection(m_roots, restriction.getRoots());
// TODO: This only works if there are equal paths in both parameter sets - for two distinct sets
// all root restrictions are dropped with an empty list.
} else {
roots = m_roots;
}
} else {
roots = restriction.getRoots();
}
// restrict categories
List categories = null;
if ((m_categories != null) && (m_categories.size() > 0)) {
if ((restriction.getCategories() != null) && (restriction.getCategories().size() > 0)) {
categories = ListUtils.intersection(m_categories, restriction.getCategories());
} else {
categories = m_categories;
}
} else {
categories = restriction.getCategories();
}
// create the new search parameters
CmsSearchParameters result = new CmsSearchParameters(
query.toString(),
fields,
roots,
categories,
m_calculateCategories,
m_sort);
result.setIndex(getIndex());
return result;
}
/**
* Set wether category counts shall be calculated for the corresponding search results or not.<p>
*
* @param flag true if category counts shall be calculated for the corresponding search results or false if not
*/
public void setCalculateCategories(boolean flag) {
m_calculateCategories = flag;
}
/**
* Set the list of categories (strings) to this parameters. <p>
*
* @param categories the list of categories (strings) of this parameters
*/
public void setCategories(List categories) {
m_categories = categories;
}
/**
* Sets the maximum number of pages which should be shown.<p>
*
* Enter an odd value to achieve a nice, "symmetric" output.<p>
*
* @param value the maximum number of pages which should be shown
*/
public void setDisplayPages(int value) {
m_displayPages = value;
}
/**
* Controls if the excerpt from a field is generated only for searched fields, or for all fields (the default).<p>
*
* @param excerptAllFields if <code>true</code>, the excerpt is generated only from the fields actually searched in
*
* @see #isExcerptOnlySearchedFields()
*/
public void setExcerptOnlySearchedFields(boolean excerptAllFields) {
m_excerptOnlySearchedFields = excerptAllFields;
}
/**
* Sets the list of strings of names of fields to search in. <p>
*
* @param fields the list of strings of names of fields to search in to set
*/
public void setFields(List fields) {
m_fields = fields;
}
/**
* Set the name of the index to search.<p>
*
*
* @param indexName the name of the index
*/
public void setIndex(String indexName) {
CmsSearchIndex index;
if (CmsStringUtil.isNotEmpty(indexName)) {
try {
index = OpenCms.getSearchManager().getIndex(indexName);
if (index == null) {
throw new CmsException(Messages.get().container(Messages.ERR_INDEX_NOT_FOUND_1, indexName));
}
setSearchIndex(index);
} catch (Exception exc) {
if (LOG.isErrorEnabled()) {
LOG.error(Messages.get().getBundle().key(Messages.LOG_INDEX_ACCESS_FAILED_1, indexName), exc);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?