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:
Serializable
,Iterable<Map.Entry<String,
,String[]>> org.apache.solr.common.MapSerializable
,org.apache.solr.common.MapWriter
,org.apache.solr.common.NavigableObject
,org.noggit.JSONWriter.Writable
A Solr search query.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.solr.client.solrj.SolrQuery
org.apache.solr.client.solrj.SolrQuery.ORDER, org.apache.solr.client.solrj.SolrQuery.SortClause
Nested classes/interfaces inherited from interface org.apache.solr.common.MapWriter
org.apache.solr.common.MapWriter.EntryWriter
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
A constant to add the score field to the result documents.static final String
The default facet date gap.static final String
The default query.static final String
The query type.static final Integer
The default search result count.static final String
A constant to add the score field to the result documents.static final String
A constant to add the score field to the result documents.Fields inherited from class org.apache.solr.client.solrj.SolrQuery
DOCID
Fields inherited from interface org.apache.solr.common.MapWriter
EMPTY
-
Constructor Summary
ConstructorDescriptionDefault constructor.CmsSolrQuery
(CmsObject cms, Map<String, String[]> queryParams) Public constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFilterQuery
(String fieldName, List<String> vals, boolean all, boolean useQuotes) Creates and adds a filter query.void
addSortFieldOrders
(Map<String, org.apache.solr.client.solrj.SolrQuery.ORDER> sortFields) Adds the given fields/orders to the existing sort fields.clone()
void
Ensures that the initial request parameters will overwrite the member values.static String
getResourceType
(String[] fqs) Returns the resource type if only one is set as filter query.void
Removes the expiration flag.void
setCategories
(String... categories) Sets the categories only if not set in the query parameters.void
setCategories
(List<String> categories) Sets the categories only if not set in the query parameters.void
Sets date ranges.void
setFacetDateGap
(String facetDateGap) Sets the facetDateGap.void
setGeoFilterQuery
(String fieldName, String coordinates, String radius, String units) Sets the Geo filter query if not exists.void
setHighlightFields
(String... highlightFields) Sets the highlightFields.void
setHighlightFields
(List<String> highlightFields) Sets the highlightFields.void
setLocales
(List<Locale> locales) Sets the locales only if not set in the query parameters.void
setLocales
(Locale... locales) Sets the locales only if not set in the query parameters.org.apache.solr.client.solrj.SolrQuery
void
setResourceTypes
(String... resourceTypes) Sets the resource types only if not set in the query parameters.void
setResourceTypes
(List<String> resourceTypes) Sets the resource types only if not set in the query parameters.void
setReturnFields
(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
(String... searchRoots) Sets the search roots only if not set as query parameter.void
setSearchRoots
(List<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
Sets the text.void
setTextSearchFields
(String... textSearchFields) Sets the textSearchFields.void
setTextSearchFields
(List<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, setShardAttributesToParams, 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
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface org.apache.solr.common.MapWriter
append, jsonStr, toMap, write
Methods inherited from interface org.apache.solr.common.NavigableObject
_forEachEntry, _forEachEntry, _forEachEntry, _get, _get, _getStr, _getStr, _size
-
Field Details
-
ALL_RETURN_FIELDS
A constant to add the score field to the result documents.- See Also:
-
DEFAULT_FACET_DATE_GAP
The default facet date gap.- See Also:
-
DEFAULT_QUERY
The default query.- See Also:
-
DEFAULT_QUERY_TYPE
The query type.- See Also:
-
DEFAULT_ROWS
The default search result count. -
MINIMUM_FIELDS
A constant to add the score field to the result documents.- See Also:
-
STRUCTURE_FIELDS
A constant to add the score field to the result documents.- See Also:
-
-
Constructor Details
-
CmsSolrQuery
public CmsSolrQuery()Default constructor. -
CmsSolrQuery
Public constructor.- Parameters:
cms
- the current OpenCms contextqueryParams
- the Solr query parameters
-
-
Method Details
-
getResourceType
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
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
Adds the given fields/orders to the existing sort fields.- Parameters:
sortFields
- the sortFields to set
-
clone
-
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
Removes the expiration flag. -
setCategories
Sets the categories only if not set in the query parameters.- Parameters:
categories
- the categories to set
-
setCategories
Sets the categories only if not set in the query parameters.- Parameters:
categories
- the categories to set
-
setDateRanges
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
Sets the facetDateGap.- Parameters:
facetDateGap
- the facetDateGap to set
-
setGeoFilterQuery
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
Sets the highlightFields.- Parameters:
highlightFields
- the highlightFields to set
-
setHighlightFields
Sets the highlightFields.- Parameters:
highlightFields
- the highlightFields to set
-
setLocales
Sets the locales only if not set in the query parameters.- Parameters:
locales
- the locales to set
-
setLocales
Sets the locales only if not set in the query parameters.- Parameters:
locales
- the locales to set
-
setRequestHandler
- Overrides:
setRequestHandler
in classorg.apache.solr.client.solrj.SolrQuery
- See Also:
-
SolrQuery.setRequestHandler(java.lang.String)
-
setResourceTypes
Sets the resource types only if not set in the query parameters.- Parameters:
resourceTypes
- the resourceTypes to set
-
setResourceTypes
Sets the resource types only if not set in the query parameters.- Parameters:
resourceTypes
- the resourceTypes to set
-
setReturnFields
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
Sets the search roots only if not set as query parameter.- Parameters:
searchRoots
- the searchRoots to set
-
setSearchRoots
Sets the search roots only if not set as query parameter.- Parameters:
searchRoots
- the searchRoots to set
-
setStructureQuery
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
Sets the text.- Parameters:
text
- the text to set
-
setTextSearchFields
Sets the textSearchFields.- Parameters:
textSearchFields
- the textSearchFields to set
-
setTextSearchFields
Sets the textSearchFields.- Parameters:
textSearchFields
- the textSearchFields to set
-