cmssearchparameters.java
来自「找了很久才找到到源代码」· Java 代码 · 共 938 行 · 第 1/3 页
JAVA
938 行
}
}
}
/**
* Sets the number of matches per page.<p>
*
* @param matches the number of matches per page
*/
public void setMatchesPerPage(int matches) {
m_matchesPerPage = matches;
}
/**
* Sets the creation date the resources have to have as maximum.<p>
*
* @param dateCreatedTo the creation date the resources have to have as maximum to set
*/
public void setMaxDateCreated(long dateCreatedTo) {
m_maxDateCreated = dateCreatedTo;
}
/**
* Sets the last modification date the resources have to have as maximum.<p>
*
* @param dateLastModifiedTo the last modification date the resources have to have as maximum to set
*/
public void setMaxDateLastModified(long dateLastModifiedTo) {
m_maxDateLastModified = dateLastModifiedTo;
}
/**
* Sets the creation date the resources have to have as minimum.<p>
*
* @param dateCreatedFrom the creation date the resources have to have as minimum to set
*/
public void setMinDateCreated(long dateCreatedFrom) {
m_minDateCreated = dateCreatedFrom;
}
/**
* Sets the last modification date the resources have to have as minimum.<p>
*
* @param dateLastModifiedFrom the the last modification date the resources have to have as minimum to set
*/
public void setMinDateLastModified(long dateLastModifiedFrom) {
m_minDateLastModified = dateLastModifiedFrom;
}
/**
* Sets the query to search for. <p>
*
* 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.<p>
*
* @param query the querye to search for to set
*
*/
public void setQuery(String query) {
// query = CmsEncoder.decode(query);
// for widget use the exception is thrown here to enforce the errmsg next to widget
if (query.trim().length() < getQueryLength()) {
throw new CmsIllegalArgumentException(Messages.get().container(
Messages.ERR_QUERY_TOO_SHORT_1,
new Integer(getQueryLength())));
}
m_query = query;
}
/**
* Sets the minimum length of the search query.<p>
*
* @param length the minimum search query length
*/
public void setQueryLength(int length) {
m_queryLength = length;
}
/**
* Sets the list of strings of roots to search under for the search.<p>
*
* @param roots the list of strings of roots to search under for the search to set
*/
public void setRoots(List roots) {
m_roots = roots;
}
/**
* Set the comma separated search root names to restrict search to.<p>
*
* @param categories the comma separated category names to restrict search to
*/
public void setSearchCategories(String categories) {
setCategories(CmsStringUtil.splitAsList(categories, ','));
}
/**
* Sets the search index to use for the search. <p>
*
* @param index the search index to use for the search to set.
*
* @throws CmsIllegalArgumentException if null is given as argument
*/
public void setSearchIndex(CmsSearchIndex index) throws CmsIllegalArgumentException {
if (index == null) {
throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_INDEX_NULL_0));
}
m_index = index;
}
/**
* Set the search page to display. <p>
*
* @param page the search page to display
*/
public void setSearchPage(int page) {
m_page = page;
}
/**
* Set the comma separated search root names to restrict search to.<p>
*
* @param rootNameList the comma separated search root names to restrict search to
*/
public void setSearchRoots(String rootNameList) {
m_roots = CmsStringUtil.splitAsList(rootNameList, ',');
}
/**
* Set the instance that defines the sort order for search results.
*
* @param sortOrder the instance that defines the sort order for search results to set
*/
public void setSort(Sort sortOrder) {
m_sort = sortOrder;
}
/**
* Sets the internal member of type <code>{@link Sort}</code> according to
* the given sort name. <p>
*
* For a list of valid sort names, please see <code>{@link #SORT_NAMES}</code>.<p>
*
* @param sortName the name of the sort to use
*
* @see #SORT_NAMES
*/
public void setSortName(String sortName) {
if (sortName.equals(SORT_NAMES[1])) {
m_sort = SORT_DATE_CREATED;
} else if (sortName.equals(SORT_NAMES[2])) {
m_sort = SORT_DATE_LASTMODIFIED;
} else if (sortName.equals(SORT_NAMES[3])) {
m_sort = SORT_TITLE;
} else {
m_sort = SORT_DEFAULT;
}
}
/**
* Creates a query String build from this search parameters for HTML links.<p>
*
* @return a query String build from this search parameters for HTML links
*/
public String toQueryString() {
StringBuffer result = new StringBuffer(128);
result.append("?action=search&query=");
result.append(CmsEncoder.encodeParameter(getQuery()));
result.append("&matchesPerPage=");
result.append(getMatchesPerPage());
result.append("&displayPages=");
result.append(getDisplayPages());
result.append("&index=");
result.append(CmsEncoder.encodeParameter(getIndex()));
Sort sort = getSort();
if (sort != CmsSearchParameters.SORT_DEFAULT) {
result.append("&sort=");
if (sort == CmsSearchParameters.SORT_TITLE) {
result.append("title");
} else if (sort == CmsSearchParameters.SORT_DATE_CREATED) {
result.append("date-created");
} else if (sort == CmsSearchParameters.SORT_DATE_LASTMODIFIED) {
result.append("date-lastmodified");
}
}
if ((getCategories() != null) && (getCategories().size() > 0)) {
result.append("&category=");
Iterator it = getCategories().iterator();
while (it.hasNext()) {
result.append(it.next());
if (it.hasNext()) {
result.append(',');
}
}
}
if ((getRoots() != null) && (getRoots().size() > 0)) {
result.append("&searchRoots=");
Iterator it = getRoots().iterator();
while (it.hasNext()) {
result.append(CmsEncoder.encode((String)it.next()));
if (it.hasNext()) {
result.append(',');
}
}
}
if (isExcerptOnlySearchedFields()) {
result.append("&excerptOnlySearchedFields=true");
}
return result.toString();
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer result = new StringBuffer();
result.append("query:[");
result.append(m_query);
result.append("] ");
if ((m_fields != null) && (m_fields.size() > 0)) {
result.append("fields:[");
for (int i = 0; i < m_fields.size(); i++) {
result.append(m_fields.get(i));
if (i + 1 < m_fields.size()) {
result.append(", ");
}
}
result.append("] ");
}
if ((m_roots != null) && (m_roots.size() > 0)) {
result.append("roots:[");
for (int i = 0; i < m_roots.size(); i++) {
result.append(m_roots.get(i));
if (i + 1 < m_roots.size()) {
result.append(", ");
}
}
result.append("] ");
}
if ((m_categories != null) && (m_categories.size() > 0)) {
result.append("categories:[");
for (int i = 0; i < m_categories.size(); i++) {
result.append(m_categories.get(i));
if (i + 1 < m_categories.size()) {
result.append(", ");
}
}
result.append("] ");
}
if (m_calculateCategories) {
result.append("calculate-categories ");
}
if (m_excerptOnlySearchedFields) {
result.append("excerpt-searched-fields-only ");
}
result.append("sort:[");
if (m_sort == CmsSearchParameters.SORT_DEFAULT) {
result.append("default");
} else if (m_sort == CmsSearchParameters.SORT_TITLE) {
result.append("title");
} else if (m_sort == CmsSearchParameters.SORT_DATE_CREATED) {
result.append("date-created");
} else if (m_sort == CmsSearchParameters.SORT_DATE_LASTMODIFIED) {
result.append("date-lastmodified");
} else {
result.append("unknown");
}
result.append("]");
return result.toString();
}
private String toSeparatedString(List stringList, char c) {
StringBuffer result = new StringBuffer();
Iterator it = stringList.iterator();
while (it.hasNext()) {
result.append(it.next());
if (it.hasNext()) {
result.append(c);
}
}
return result.toString();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?