Package org.opencms.search
Class CmsSearchUtil
java.lang.Object
org.opencms.search.CmsSearchUtil
Provides common functions regarding searching.
- Since:
- 9.0.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Collection<String>
A suite of default date formats that can be parsed, and thus transformed to the Solr specific formatstatic final String
Date format pattern used to parse HTTP date headers in ANSI Casctime()
format.static final String
Date format pattern used to parse HTTP date headers in RFC 1036 format.static final String
Date format pattern used to parse HTTP date headers in RFC 1123 format.static final TimeZone
Variable to hold an GMT timezone object.static final TimeZone
Variable to hold an UTC timezone object. -
Method Summary
Modifier and TypeMethodDescriptioncomputeScopeFolders
(CmsObject cms, CmsGallerySearchParameters params) Computes the search root folders for the given search parameters based on the search scope.static String
getDateAsIso8601
(long date) Returns a given date object in the ISO 8601 format.static String
getDateAsIso8601
(Date date) Returns a given date object in the ISO 8601 format.static String
getDateCreatedTimeRangeFilterQuery
(String searchField, long startTime, long endTime) Returns a time interval as Solr compatible query string.getSearchRootsForScope
(CmsGallerySearchScope scope, String siteParam, String subSiteParam) Gets the search roots to use for the given site/subsite parameters.static String
getSolrRangeString
(String from, String to) Returns a string that represents a valid Solr query range.static Date
Returns a formatter that can be use by the current thread if needed to convert Date objects to the Internal representation.static Date
parseDate
(String d, Collection<String> fmts) static Date
parseDate
(String dateValue, Collection<String> dateFormats, Date startDate) Slightly modified from org.apache.commons.httpclient.util.DateUtil.parseDatestatic String
stripHtmlFromPropertyIfNecessary
(String propertyName, String value) Strips of HTML of the value to map, if necessary (depending on the property name).static Collection<org.apache.solr.common.util.ContentStream>
toContentStreams
(String str, String contentType) Take a string and make it an iterable ContentStreamstatic org.apache.solr.common.SolrDocument
toSolrDocument
(org.apache.solr.common.SolrInputDocument d) Deprecated.This method will be removed in Solr 6.0static org.apache.solr.common.SolrInputDocument
toSolrInputDocument
(org.apache.solr.common.SolrDocument d) Deprecated.This method will be removed in Solr 6.0
-
Field Details
-
TIMEZONE_UTC
Variable to hold an UTC timezone object. -
TIMEZONE_GMT
Variable to hold an GMT timezone object. -
PATTERN_RFC1123
Date format pattern used to parse HTTP date headers in RFC 1123 format.- See Also:
-
PATTERN_RFC1036
Date format pattern used to parse HTTP date headers in RFC 1036 format.- See Also:
-
PATTERN_ASCTIME
Date format pattern used to parse HTTP date headers in ANSI Casctime()
format.- See Also:
-
DEFAULT_DATE_FORMATS
A suite of default date formats that can be parsed, and thus transformed to the Solr specific format
-
-
Method Details
-
computeScopeFolders
Computes the search root folders for the given search parameters based on the search scope.- Parameters:
cms
- the current CMS contextparams
- the current search parameters- Returns:
- the search root folders based on the search scope
-
getDateAsIso8601
Returns a given date object in the ISO 8601 format.- Parameters:
date
- that should be converted.- Returns:
- string that represents the given date in the ISO 8601 format.
-
getDateAsIso8601
Returns a given date object in the ISO 8601 format.- Parameters:
date
- that should be converted.- Returns:
- string that represents the given date in the ISO 8601 format.
-
getDateCreatedTimeRangeFilterQuery
public static String getDateCreatedTimeRangeFilterQuery(String searchField, long startTime, long endTime) Returns a time interval as Solr compatible query string.- Parameters:
searchField
- the field to search for.startTime
- the lower limit of the interval.endTime
- the upper limit of the interval.- Returns:
- Solr compatible query string.
-
getSolrRangeString
Returns a string that represents a valid Solr query range.- Parameters:
from
- Lower bound of the query range.to
- Upper bound of the query range.- Returns:
- String that represents a Solr query range.
-
parseDate
Returns a formatter that can be use by the current thread if needed to convert Date objects to the Internal representation.- Parameters:
d
- The input date to parse- Returns:
- The parsed
Date
- Throws:
ParseException
- If the input can't be parsed
-
parseDate
- Throws:
ParseException
-
parseDate
public static Date parseDate(String dateValue, Collection<String> dateFormats, Date startDate) throws ParseException Slightly modified from org.apache.commons.httpclient.util.DateUtil.parseDateParses the date value using the given date formats.
- Parameters:
dateValue
- the date value to parsedateFormats
- the date formats to usestartDate
- During parsing, two digit years will be placed in the rangestartDate
tostartDate + 100 years
. This value may benull
. Whennull
is given as a parameter, year2000
will be used.- Returns:
- the parsed date
- Throws:
ParseException
- if none of the dataFormats could parse the dateValue
-
stripHtmlFromPropertyIfNecessary
Strips of HTML of the value to map, if necessary (depending on the property name).- Parameters:
propertyName
- name of the property.value
- the properties value (possibly with HTML)- Returns:
- the value with HTML stripped of, or the original value, if stripping of the HTML fails.
-
toContentStreams
public static Collection<org.apache.solr.common.util.ContentStream> toContentStreams(String str, String contentType) Take a string and make it an iterable ContentStream -
toSolrDocument
@Deprecated public static org.apache.solr.common.SolrDocument toSolrDocument(org.apache.solr.common.SolrInputDocument d) Deprecated.This method will be removed in Solr 6.0- Parameters:
d
- SolrInputDocument to convert- Returns:
- a SolrDocument with the same fields and values as the SolrInputDocument
-
toSolrInputDocument
@Deprecated public static org.apache.solr.common.SolrInputDocument toSolrInputDocument(org.apache.solr.common.SolrDocument d) Deprecated.This method will be removed in Solr 6.0- Parameters:
d
- SolrDocument to convert- Returns:
- a SolrInputDocument with the same fields and values as the SolrDocument.
-