Package org.opencms.search.solr
Class CmsSolrQuery
- java.lang.Object
-
- org.apache.solr.common.params.SolrParams
-
- org.apache.solr.common.params.ModifiableSolrParams
-
- org.apache.solr.client.solrj.SolrQuery
-
- org.opencms.search.solr.CmsSolrQuery
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String[]>>
,org.apache.solr.common.MapSerializable
,org.apache.solr.common.MapWriter
,org.apache.solr.common.NavigableObject
public class CmsSolrQuery extends org.apache.solr.client.solrj.SolrQuery
A Solr search query.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ALL_RETURN_FIELDS
A constant to add the score field to the result documents.static java.lang.String
DEFAULT_FACET_DATE_GAP
The default facet date gap.static java.lang.String
DEFAULT_QUERY
The default query.static java.lang.String
DEFAULT_QUERY_TYPE
The query type.static java.lang.Integer
DEFAULT_ROWS
The default search result count.static java.lang.String
MINIMUM_FIELDS
A constant to add the score field to the result documents.static java.lang.String
STRUCTURE_FIELDS
A constant to add the score field to the result documents.
-
Constructor Summary
Constructors Constructor Description CmsSolrQuery()
Default constructor.CmsSolrQuery(CmsObject cms, java.util.Map<java.lang.String,java.lang.String[]> queryParams)
Public constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFilterQuery(java.lang.String fieldName, java.util.List<java.lang.String> vals, boolean all, boolean useQuotes)
Creates and adds a filter query.void
addSortFieldOrders(java.util.Map<java.lang.String,org.apache.solr.client.solrj.SolrQuery.ORDER> sortFields)
Adds the given fields/orders to the existing sort fields.CmsSolrQuery
clone()
void
ensureParameters()
Ensures that the initial request parameters will overwrite the member values.static java.lang.String
getResourceType(java.lang.String[] fqs)
Returns the resource type if only one is set as filter query.void
removeExpiration()
Removes the expiration flag.void
setCategories(java.lang.String... categories)
Sets the categories only if not set in the query parameters.void
setCategories(java.util.List<java.lang.String> categories)
Sets the categories only if not set in the query parameters.void
setDateRanges(java.util.Map<java.lang.String,CmsPair<java.util.Date,java.util.Date>> dateRanges)
Sets date ranges.void
setFacetDateGap(java.lang.String facetDateGap)
Sets the facetDateGap.void
setGeoFilterQuery(java.lang.String fieldName, java.lang.String coordinates, java.lang.String radius, java.lang.String units)
Sets the Geo filter query if not exists.void
setHighlightFields(java.lang.String... highlightFields)
Sets the highlightFields.void
setHighlightFields(java.util.List<java.lang.String> highlightFields)
Sets the highlightFields.void
setLocales(java.util.List<java.util.Locale> locales)
Sets the locales only if not set in the query parameters.void
setLocales(java.util.Locale... locales)
Sets the locales only if not set in the query parameters.org.apache.solr.client.solrj.SolrQuery
setRequestHandler(java.lang.String qt)
void
setResourceTypes(java.lang.String... resourceTypes)
Sets the resource types only if not set in the query parameters.void
setResourceTypes(java.util.List<java.lang.String> resourceTypes)
Sets the resource types only if not set in the query parameters.void
setReturnFields(java.lang.String returnFields)
Sets the requested return fields, but ensures that at least the 'path' and the 'type', 'id' and 'solr_id' are part of the fields returned field list.void
setSearchRoots(java.lang.String... searchRoots)
Sets the search roots only if not set as query parameter.void
setSearchRoots(java.util.List<java.lang.String> searchRoots)
Sets the search roots only if not set as query parameter.void
setStructureQuery(boolean structureQuery)
Sets the return fields 'fl' to a predefined set that does not contain content specific fields.void
setText(java.lang.String text)
Sets the text.void
setTextSearchFields(java.lang.String... textSearchFields)
Sets the textSearchFields.void
setTextSearchFields(java.util.List<java.lang.String> textSearchFields)
Sets the textSearchFields.-
Methods inherited from class org.apache.solr.client.solrj.SolrQuery
addDateRangeFacet, addFacetField, addFacetPivotField, addFacetQuery, addField, addFilterQuery, addGetFieldStatistics, addHighlightField, addIntervalFacets, addMoreLikeThisField, addNumericRangeFacet, addOrUpdateSort, addOrUpdateSort, addSort, addSort, addStatsFieldCalcDistinct, addStatsFieldFacets, addTermsField, clearSorts, getCopy, getFacetFields, getFacetLimit, getFacetMinCount, getFacetQuery, getFacetSortString, getFields, getFilterQueries, getHighlight, getHighlightFields, getHighlightFragsize, getHighlightRequireFieldMatch, getHighlightSimplePost, getHighlightSimplePre, getHighlightSnippets, getMoreLikeThis, getMoreLikeThisBoost, getMoreLikeThisCount, getMoreLikeThisFields, getMoreLikeThisMaxQueryTerms, getMoreLikeThisMaxTokensParsed, getMoreLikeThisMaxWordLen, getMoreLikeThisMinDocFreq, getMoreLikeThisMinTermFreq, getMoreLikeThisMinWordLen, getMoreLikeThisQF, getQuery, getRequestHandler, getRows, getSortField, getSorts, getStart, getTerms, getTermsFields, getTermsLimit, getTermsLower, getTermsLowerInclusive, getTermsMaxCount, getTermsMinCount, getTermsPrefix, getTermsRaw, getTermsRegex, getTermsRegexFlags, getTermsSortString, getTermsUpper, getTermsUpperInclusive, getTimeAllowed, removeFacetField, removeFacetQuery, removeFilterQuery, removeHighlightField, removeIntervalFacets, removeSort, removeSort, setDistrib, setFacet, setFacetLimit, setFacetMinCount, setFacetMissing, setFacetPrefix, setFacetPrefix, setFacetSort, setFields, setFilterQueries, setGetFieldStatistics, setGetFieldStatistics, setHighlight, setHighlightFragsize, setHighlightRequireFieldMatch, setHighlightSimplePost, setHighlightSimplePre, setHighlightSnippets, setIncludeScore, setMoreLikeThis, setMoreLikeThisBoost, setMoreLikeThisCount, setMoreLikeThisFields, setMoreLikeThisMaxQueryTerms, setMoreLikeThisMaxTokensParsed, setMoreLikeThisMaxWordLen, setMoreLikeThisMinDocFreq, setMoreLikeThisMinTermFreq, setMoreLikeThisMinWordLen, setMoreLikeThisQF, setParam, setParam, setQuery, setRows, setShowDebugInfo, setSort, setSort, setSorts, setStart, setTerms, setTermsLimit, setTermsLower, setTermsLowerInclusive, setTermsMaxCount, setTermsMinCount, setTermsPrefix, setTermsRaw, setTermsRegex, setTermsRegexFlag, setTermsSortString, setTermsUpper, setTermsUpperInclusive, setTimeAllowed
-
Methods inherited from class org.apache.solr.common.params.ModifiableSolrParams
add, add, clear, get, getMap, getParameterNames, getParameterNamesIterator, getParams, iterator, of, remove, remove, set, set, set, setNonNull, size
-
Methods inherited from class org.apache.solr.common.params.SolrParams
fpname, get, getAll, getAll, getBool, getBool, getDouble, getDouble, getFieldBool, getFieldBool, getFieldDouble, getFieldDouble, getFieldFloat, getFieldFloat, getFieldInt, getFieldInt, getFieldParam, getFieldParam, getFieldParams, getFloat, getFloat, getInt, getInt, getLong, getLong, getPrimitiveBool, getPrimitiveFieldBool, getPrimitiveFieldFloat, getPrimitiveInt, required, stream, toFilteredSolrParams, toLocalParamsString, toMap, toMultiMap, toNamedList, toQueryString, toSolrParams, toString, wrapAppended, wrapDefaults, writeMap
-
-
-
-
Field Detail
-
ALL_RETURN_FIELDS
public static final java.lang.String ALL_RETURN_FIELDS
A constant to add the score field to the result documents.- See Also:
- Constant Field Values
-
DEFAULT_FACET_DATE_GAP
public static final java.lang.String DEFAULT_FACET_DATE_GAP
The default facet date gap.- See Also:
- Constant Field Values
-
DEFAULT_QUERY
public static final java.lang.String DEFAULT_QUERY
The default query.- See Also:
- Constant Field Values
-
DEFAULT_QUERY_TYPE
public static final java.lang.String DEFAULT_QUERY_TYPE
The query type.- See Also:
- Constant Field Values
-
DEFAULT_ROWS
public static final java.lang.Integer DEFAULT_ROWS
The default search result count.
-
MINIMUM_FIELDS
public static final java.lang.String MINIMUM_FIELDS
A constant to add the score field to the result documents.- See Also:
- Constant Field Values
-
STRUCTURE_FIELDS
public static final java.lang.String STRUCTURE_FIELDS
A constant to add the score field to the result documents.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CmsSolrQuery
public CmsSolrQuery()
Default constructor.
-
CmsSolrQuery
public CmsSolrQuery(CmsObject cms, java.util.Map<java.lang.String,java.lang.String[]> queryParams)
Public constructor.- Parameters:
cms
- the current OpenCms contextqueryParams
- the Solr query parameters
-
-
Method Detail
-
getResourceType
public static java.lang.String getResourceType(java.lang.String[] fqs)
Returns the resource type if only one is set as filter query.- Parameters:
fqs
- the field queries to check- Returns:
- the type or
null
-
addFilterQuery
public void addFilterQuery(java.lang.String fieldName, java.util.List<java.lang.String> vals, boolean all, boolean useQuotes)
Creates and adds a filter query.- Parameters:
fieldName
- the field name to create a filter query onvals
- the values that should match for the given fieldall
-true
to combine the given values with 'AND',false
for 'OR'useQuotes
-true
to surround the given values with double quotes,false
otherwise
-
addSortFieldOrders
public void addSortFieldOrders(java.util.Map<java.lang.String,org.apache.solr.client.solrj.SolrQuery.ORDER> sortFields)
Adds the given fields/orders to the existing sort fields.- Parameters:
sortFields
- the sortFields to set
-
clone
public CmsSolrQuery clone()
- Overrides:
clone
in classjava.lang.Object
- See Also:
Object.clone()
-
ensureParameters
public void ensureParameters()
Ensures that the initial request parameters will overwrite the member values.You can initialize the query with an HTTP request parameter then make some method calls and finally re-ensure that the initial request parameters will overwrite the changes made in the meanwhile.
-
removeExpiration
public void removeExpiration()
Removes the expiration flag.
-
setCategories
public void setCategories(java.util.List<java.lang.String> categories)
Sets the categories only if not set in the query parameters.- Parameters:
categories
- the categories to set
-
setCategories
public void setCategories(java.lang.String... categories)
Sets the categories only if not set in the query parameters.- Parameters:
categories
- the categories to set
-
setDateRanges
public void setDateRanges(java.util.Map<java.lang.String,CmsPair<java.util.Date,java.util.Date>> dateRanges)
Sets date ranges.This call will overwrite all existing date ranges for the given keys (name of the date facet field).
The parameter Map uses as:
keys:
Solr field nameCmsSearchField
andvalues:
pairs with min date as first and max date as secondCmsPair
+created:[* TO NOW]
+lastmodified:[' + date + ' TO NOW]
CmsSearchUtil.getDateAsIso8601(Date)
- Parameters:
dateRanges
- the ranges map with field name as key and a CmsPair with min date as first and max date as second
-
setFacetDateGap
public void setFacetDateGap(java.lang.String facetDateGap)
Sets the facetDateGap.- Parameters:
facetDateGap
- the facetDateGap to set
-
setGeoFilterQuery
public void setGeoFilterQuery(java.lang.String fieldName, java.lang.String coordinates, java.lang.String radius, java.lang.String units)
Sets the Geo filter query if not exists.- Parameters:
fieldName
- the field name storing the coordinatescoordinates
- the coordinates string as a lat,lng pairradius
- the radiusunits
- the units of the search radius
-
setHighlightFields
public void setHighlightFields(java.util.List<java.lang.String> highlightFields)
Sets the highlightFields.- Parameters:
highlightFields
- the highlightFields to set
-
setHighlightFields
public void setHighlightFields(java.lang.String... highlightFields)
Sets the highlightFields.- Parameters:
highlightFields
- the highlightFields to set
-
setLocales
public void setLocales(java.util.List<java.util.Locale> locales)
Sets the locales only if not set in the query parameters.- Parameters:
locales
- the locales to set
-
setLocales
public void setLocales(java.util.Locale... locales)
Sets the locales only if not set in the query parameters.- Parameters:
locales
- the locales to set
-
setRequestHandler
public org.apache.solr.client.solrj.SolrQuery setRequestHandler(java.lang.String qt)
- Overrides:
setRequestHandler
in classorg.apache.solr.client.solrj.SolrQuery
- See Also:
SolrQuery.setRequestHandler(java.lang.String)
-
setResourceTypes
public void setResourceTypes(java.util.List<java.lang.String> resourceTypes)
Sets the resource types only if not set in the query parameters.- Parameters:
resourceTypes
- the resourceTypes to set
-
setResourceTypes
public void setResourceTypes(java.lang.String... resourceTypes)
Sets the resource types only if not set in the query parameters.- Parameters:
resourceTypes
- the resourceTypes to set
-
setReturnFields
public void setReturnFields(java.lang.String returnFields)
Sets the requested return fields, but ensures that at least the 'path' and the 'type', 'id' and 'solr_id' are part of the fields returned field list.- Parameters:
returnFields
- the really requested return fields.- See Also:
CommonParams.FL
-
setSearchRoots
public void setSearchRoots(java.util.List<java.lang.String> searchRoots)
Sets the search roots only if not set as query parameter.- Parameters:
searchRoots
- the searchRoots to set
-
setSearchRoots
public void setSearchRoots(java.lang.String... searchRoots)
Sets the search roots only if not set as query parameter.- Parameters:
searchRoots
- the searchRoots to set
-
setStructureQuery
public void setStructureQuery(boolean structureQuery)
Sets the return fields 'fl' to a predefined set that does not contain content specific fields.- Parameters:
structureQuery
- thetrue
to return only structural fields
-
setText
public void setText(java.lang.String text)
Sets the text.- Parameters:
text
- the text to set
-
setTextSearchFields
public void setTextSearchFields(java.util.List<java.lang.String> textSearchFields)
Sets the textSearchFields.- Parameters:
textSearchFields
- the textSearchFields to set
-
setTextSearchFields
public void setTextSearchFields(java.lang.String... textSearchFields)
Sets the textSearchFields.- Parameters:
textSearchFields
- the textSearchFields to set
-
-