Package org.opencms.search
Class CmsSearchUtil
- java.lang.Object
-
- org.opencms.search.CmsSearchUtil
-
public final class CmsSearchUtil extends java.lang.Object
Provides common functions regarding searching.- Since:
- 9.0.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Collection<java.lang.String>
DEFAULT_DATE_FORMATS
A suite of default date formats that can be parsed, and thus transformed to the Solr specific formatstatic java.lang.String
PATTERN_ASCTIME
Date format pattern used to parse HTTP date headers in ANSI Casctime()
format.static java.lang.String
PATTERN_RFC1036
Date format pattern used to parse HTTP date headers in RFC 1036 format.static java.lang.String
PATTERN_RFC1123
Date format pattern used to parse HTTP date headers in RFC 1123 format.static java.util.TimeZone
TIMEZONE_GMT
Variable to hold an GMT timezone object.static java.util.TimeZone
TIMEZONE_UTC
Variable to hold an UTC timezone object.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.util.List<java.lang.String>
computeScopeFolders(CmsObject cms, CmsGallerySearchParameters params)
Computes the search root folders for the given search parameters based on the search scope.static java.lang.String
getDateAsIso8601(long date)
Returns a given date object in the ISO 8601 format.static java.lang.String
getDateAsIso8601(java.util.Date date)
Returns a given date object in the ISO 8601 format.static java.lang.String
getDateCreatedTimeRangeFilterQuery(java.lang.String searchField, long startTime, long endTime)
Returns a time interval as Solr compatible query string.static java.util.List<java.lang.String>
getSearchRootsForScope(CmsGallerySearchScope scope, java.lang.String siteParam, java.lang.String subSiteParam)
Gets the search roots to use for the given site/subsite parameters.static java.lang.String
getSolrRangeString(java.lang.String from, java.lang.String to)
Returns a string that represents a valid Solr query range.static java.util.Date
parseDate(java.lang.String d)
Returns a formatter that can be use by the current thread if needed to convert Date objects to the Internal representation.static java.util.Date
parseDate(java.lang.String d, java.util.Collection<java.lang.String> fmts)
static java.util.Date
parseDate(java.lang.String dateValue, java.util.Collection<java.lang.String> dateFormats, java.util.Date startDate)
Slightly modified from org.apache.commons.httpclient.util.DateUtil.parseDatestatic java.lang.String
stripHtmlFromPropertyIfNecessary(java.lang.String propertyName, java.lang.String value)
Strips of HTML of the value to map, if necessary (depending on the property name).static java.util.Collection<org.apache.solr.common.util.ContentStream>
toContentStreams(java.lang.String str, java.lang.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 Detail
-
TIMEZONE_UTC
public static final java.util.TimeZone TIMEZONE_UTC
Variable to hold an UTC timezone object.
-
TIMEZONE_GMT
public static final java.util.TimeZone TIMEZONE_GMT
Variable to hold an GMT timezone object.
-
PATTERN_RFC1123
public static final java.lang.String PATTERN_RFC1123
Date format pattern used to parse HTTP date headers in RFC 1123 format.- See Also:
- Constant Field Values
-
PATTERN_RFC1036
public static final java.lang.String PATTERN_RFC1036
Date format pattern used to parse HTTP date headers in RFC 1036 format.- See Also:
- Constant Field Values
-
PATTERN_ASCTIME
public static final java.lang.String PATTERN_ASCTIME
Date format pattern used to parse HTTP date headers in ANSI Casctime()
format.- See Also:
- Constant Field Values
-
DEFAULT_DATE_FORMATS
public static final java.util.Collection<java.lang.String> DEFAULT_DATE_FORMATS
A suite of default date formats that can be parsed, and thus transformed to the Solr specific format
-
-
Method Detail
-
computeScopeFolders
public static java.util.List<java.lang.String> computeScopeFolders(CmsObject cms, CmsGallerySearchParameters params)
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
public static java.lang.String getDateAsIso8601(java.util.Date date)
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
public static java.lang.String getDateAsIso8601(long date)
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 java.lang.String getDateCreatedTimeRangeFilterQuery(java.lang.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.
-
getSearchRootsForScope
public static java.util.List<java.lang.String> getSearchRootsForScope(CmsGallerySearchScope scope, java.lang.String siteParam, java.lang.String subSiteParam)
Gets the search roots to use for the given site/subsite parameters.- Parameters:
scope
- the search scopesiteParam
- the current sitesubSiteParam
- the current subsite- Returns:
- the list of search roots for that option
-
getSolrRangeString
public static java.lang.String getSolrRangeString(java.lang.String from, java.lang.String to)
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
public static java.util.Date parseDate(java.lang.String d) throws java.text.ParseException
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:
java.text.ParseException
- If the input can't be parsed
-
parseDate
public static java.util.Date parseDate(java.lang.String d, java.util.Collection<java.lang.String> fmts) throws java.text.ParseException
- Throws:
java.text.ParseException
-
parseDate
public static java.util.Date parseDate(java.lang.String dateValue, java.util.Collection<java.lang.String> dateFormats, java.util.Date startDate) throws java.text.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:
java.text.ParseException
- if none of the dataFormats could parse the dateValue
-
stripHtmlFromPropertyIfNecessary
public static java.lang.String stripHtmlFromPropertyIfNecessary(java.lang.String propertyName, java.lang.String value)
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 java.util.Collection<org.apache.solr.common.util.ContentStream> toContentStreams(java.lang.String str, java.lang.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.
-
-