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.SortClauseNested classes/interfaces inherited from interface org.apache.solr.common.MapWriter
org.apache.solr.common.MapWriter.EntryWriter -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringA constant to add the score field to the result documents.static final StringThe default facet date gap.static final StringThe default query.static final StringThe query type.static final IntegerThe default search result count.static final StringA constant to add the score field to the result documents.static final StringA constant to add the score field to the result documents.Fields inherited from class org.apache.solr.client.solrj.SolrQuery
DOCIDFields inherited from interface org.apache.solr.common.MapWriter
EMPTY -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.CmsSolrQuery(CmsObject cms, Map<String, String[]> queryParams) Public constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFilterQuery(String fieldName, List<String> vals, boolean all, boolean useQuotes) Creates and adds a filter query.voidaddSortFieldOrders(Map<String, org.apache.solr.client.solrj.SolrQuery.ORDER> sortFields) Adds the given fields/orders to the existing sort fields.clone()voidEnsures that the initial request parameters will overwrite the member values.static StringgetResourceType(String[] fqs) Returns the resource type if only one is set as filter query.voidRemoves the expiration flag.voidsetCategories(String... categories) Sets the categories only if not set in the query parameters.voidsetCategories(List<String> categories) Sets the categories only if not set in the query parameters.voidSets date ranges.voidsetFacetDateGap(String facetDateGap) Sets the facetDateGap.voidsetGeoFilterQuery(String fieldName, String coordinates, String radius, String units) Sets the Geo filter query if not exists.voidsetHighlightFields(String... highlightFields) Sets the highlightFields.voidsetHighlightFields(List<String> highlightFields) Sets the highlightFields.voidsetLocales(List<Locale> locales) Sets the locales only if not set in the query parameters.voidsetLocales(Locale... locales) Sets the locales only if not set in the query parameters.org.apache.solr.client.solrj.SolrQueryvoidsetResourceTypes(String... resourceTypes) Sets the resource types only if not set in the query parameters.voidsetResourceTypes(List<String> resourceTypes) Sets the resource types only if not set in the query parameters.voidsetReturnFields(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.voidsetSearchRoots(String... searchRoots) Sets the search roots only if not set as query parameter.voidsetSearchRoots(List<String> searchRoots) Sets the search roots only if not set as query parameter.voidsetStructureQuery(boolean structureQuery) Sets the return fields 'fl' to a predefined set that does not contain content specific fields.voidSets the text.voidsetTextSearchFields(String... textSearchFields) Sets the textSearchFields.voidsetTextSearchFields(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, getCpuAllowed, 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, setCpuAllowed, 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, setTimeAllowedMethods 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, sizeMethods inherited from class org.apache.solr.common.params.SolrParams
fpname, get, 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, toLocalParamsString, toNamedList, toQueryString, toString, wrapAppended, wrapDefaults, writeMapMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface org.apache.solr.common.MapWriter
append, jsonStr, toMap, writeMethods 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-trueto combine the given values with 'AND',falsefor 'OR'useQuotes-trueto surround the given values with double quotes,falseotherwise
-
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 nameCmsSearchFieldandvalues: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:
setRequestHandlerin classorg.apache.solr.client.solrj.SolrQuery- See Also:
-
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:
-
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- thetrueto 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
-