Class CmsSolrIndex
- All Implemented Interfaces:
Serializable
,I_CmsConfigurationParameterHandler
,I_CmsSearchIndex
- Since:
- 8.5.0
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final int
A constant for debug formatting output.static final String
The name of the default Solr Offline index.static final String
The name of the default Solr Online index.static final int
The constant for an unlimited maximum number of results to return in a Solr search.static final int
The constant for an unlimited maximum number of results to return in a Solr search.static final String
Constant for additional parameter to set the post processor class name.static final String
The solr exclude property.static final int
Indicates the maximum number of documents from the complete result set to return.static final String
Constant for additional parameter to set the fields the select handler should return at maximum.static final String
Constant for additional parameter to set the maximal number of a result, the select handler should return.static final String
Constant for additional parameter to set the number results the select handler should return at maxium per request.static final String
Constant for additional parameter to set the maximally processed results (start + rows) for searches with this index.Fields inherited from class org.opencms.search.CmsSearchIndex
A_PARAM_PREFIX, BACKUP_REINDEXING, DATES, DOC_META_FIELDS, EXCERPT, EXTRACT_CONTENT, IGNORE_EXPIRATION, LANGUAGEDETECTION, LUCENE_AUTO_COMMIT, LUCENE_RAM_BUFFER_SIZE_MB, MAX_HITS, MAX_HITS_DEFAULT, MAX_YEAR_RANGE, PERMISSIONS, PRIORITY, TIME_RANGE, VISITOR
Fields inherited from class org.opencms.search.A_CmsSearchIndex
PROPERTY_SEARCH_EXCLUDE_VALUE_ALL, PROPERTY_SEARCH_EXCLUDE_VALUE_GALLERY, USE_ALL_LOCALE
Fields inherited from interface org.opencms.configuration.I_CmsConfigurationParameterHandler
ADD_PARAMETER_METHOD, INIT_CONFIGURATION_METHOD
Fields inherited from interface org.opencms.search.I_CmsSearchIndex
REBUILD_MODE_AUTO, REBUILD_MODE_MANUAL, REBUILD_MODE_NEVER, REBUILD_MODE_OFFLINE
-
Constructor Summary
ConstructorDescriptionDefault constructor.CmsSolrIndex
(String name) Public constructor to create a Solr index. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addConfigurationParameter
(String key, String value) Adds a parameter.createEmptyDocument
(CmsResource resource) Creates an empty document that can be used by this search field configuration.protected String
Creates a backup of this index for optimized re-indexing of the whole content.createIndexWriter
(boolean create, I_CmsReport report) Creates a new index writer.boolean
excludeFromIndex
(CmsObject cms, CmsResource resource) Checks if the provided resource should be excluded from this search index.gallerySearch
(CmsObject cms, CmsGallerySearchParameters params) Performs a search with according to the gallery search parameters.Returns the empty configuration.Returns the name of the core of the index.getDocument
(String fieldname, String term) Returns the first document where the given term matches the selected index field.getDocument
(String fieldname, String term, String[] fls) Version ofCmsSearchIndex.getDocument(java.lang.String, java.lang.String)
where the returned fields can be restricted.getLocaleForResource
(CmsObject cms, CmsResource resource, List<Locale> availableLocales) Returns the language locale for the given resource in this index.int
Returns the maximal number of results (start + rows) that are processed for each search query unless another maximum is explicitly specified insearch(CmsObject, CmsSolrQuery, boolean, ServletResponse, boolean, CmsResourceFilter, int)
.Returns the search post processor.Returns the Solr server URL to connect to for this specific index, ornull
if no specific URL is configured.static final String
Returns the resource type for the given root path.protected boolean
hasPermissions
(CmsObject cms, CmsSolrDocument doc, CmsResourceFilter filter) Check, if the current user has permissions on the document's resource.protected void
Closes the index searcher for this index.protected void
indexSearcherOpen
(String path) Initializes the index searcher for this index.protected void
Reopens the index search reader for this index, required after the index has been changed.void
Initializes the search index.boolean
Returns a flag, indicating if the Solr server is not yet set.Performs a search.Default search method.search
(CmsObject cms, CmsSearchParameters params) Deprecated.search
(CmsObject cms, CmsSolrQuery query) Default search method.search
(CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows) Performs a search.search
(CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows, javax.servlet.ServletResponse response, boolean ignoreSearchExclude, CmsResourceFilter filter) Performs the actual search.search
(CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows, javax.servlet.ServletResponse response, boolean ignoreSearchExclude, CmsResourceFilter filter, int maxNumResults) Performs the actual search.search
(CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows, CmsResourceFilter filter) Likesearch(CmsObject, CmsSolrQuery, boolean)
, but additionally a resource filter can be specified.void
select
(javax.servlet.ServletResponse response, CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows) Writes the response into the writer.void
Sets the logical key/name of this search index.void
setPostProcessor
(I_CmsSolrPostSearchProcessor postProcessor) Sets the search post processor.void
setSolrServer
(org.apache.solr.client.solrj.SolrClient client) Sets the Solr server used by this index.void
spellCheck
(javax.servlet.ServletResponse res, CmsObject cms, CmsSolrQuery q) Executes a spell checking Solr query and returns the Solr query response.Methods inherited from class org.opencms.search.CmsSearchIndex
appendCategoryFilter, appendDateCreatedFilter, appendDateLastModifiedFilter, appendPathFilter, appendResourceTypeFilter, createDateRangeFilter, extendPathFilter, generateIndexDirectory, getAnalyzer, getContentIfUnchanged, getDateRangeSpan, getDocument, getDocument, getLocaleString, getMaxHits, getMultiTermQueryFilter, getMultiTermQueryFilter, getMultiTermQueryFilter, getPath, getPriority, getResource, getResource, getSearcher, getTermQueryFilter, hasReadPermission, indexSearcherClose, isBackupReindexing, isCheckingPermissions, isCheckingTimeRange, isCheckPermissions, isCreatingExcerpt, isIgnoreExpiration, isInitialized, isInTimeRange, isRequireViewPermission, isSortScoring, needsPermissionCheck, onIndexChanged, removeIndexBackup, setAnalyzer, setCheckPermissions, setIgnoreExpiration, setMaxHits, setRequireViewPermission, shutDown, toString
Methods inherited from class org.opencms.search.A_CmsSearchIndex
addSourceName, checkConfiguration, equals, getDocumentFactory, getFieldConfiguration, getFieldConfigurationName, getIndexWriter, getLocale, getName, getProject, getRebuildMode, getSourceNames, getSources, hashCode, initConfiguration, isEnabled, isExtractingContent, isIndexing, isLanguageDetection, isUpdatedIncremental, removeSourceName, setEnabled, setExtractContent, setFieldConfiguration, setFieldConfigurationName, setIndexWriter, setLanguageDetection, setLocale, setLocaleString, setPath, setProject, setRebuildMode
-
Field Details
-
DEFAULT_INDEX_NAME_OFFLINE
The name of the default Solr Offline index.- See Also:
-
DEFAULT_INDEX_NAME_ONLINE
The name of the default Solr Online index.- See Also:
-
POST_PROCESSOR
Constant for additional parameter to set the post processor class name.- See Also:
-
SOLR_SEARCH_MAX_PROCESSED_RESULTS
Constant for additional parameter to set the maximally processed results (start + rows) for searches with this index. It overwrites the global configuration fromCmsSolrConfiguration.getMaxProcessedResults()
for this index.- See Also:
-
SOLR_HANDLER_ALLOWED_FIELDS
Constant for additional parameter to set the fields the select handler should return at maximum.- See Also:
-
SOLR_HANDLER_MAX_ALLOWED_RESULTS_PER_PAGE
Constant for additional parameter to set the number results the select handler should return at maxium per request.- See Also:
-
SOLR_HANDLER_MAX_ALLOWED_RESULTS_AT_ALL
Constant for additional parameter to set the maximal number of a result, the select handler should return.- See Also:
-
PROPERTY_SEARCH_EXCLUDE_VALUE_SOLR
The solr exclude property.- See Also:
-
ROWS_MAX
Indicates the maximum number of documents from the complete result set to return.- See Also:
-
MAX_RESULTS_UNLIMITED
The constant for an unlimited maximum number of results to return in a Solr search.- See Also:
-
MAX_RESULTS_GALLERY
The constant for an unlimited maximum number of results to return in a Solr search.- See Also:
-
DEBUG_PADDING_RIGHT
A constant for debug formatting output.- See Also:
-
-
Constructor Details
-
CmsSolrIndex
public CmsSolrIndex()Default constructor. -
CmsSolrIndex
Public constructor to create a Solr index.- Parameters:
name
- the name for this index.- Throws:
CmsIllegalArgumentException
- if something goes wrong
-
-
Method Details
-
getType
Returns the resource type for the given root path.- Parameters:
cms
- the current CMS contextrootPath
- the root path of the resource to get the type for- Returns:
- the resource type for the given root path
-
addConfigurationParameter
Description copied from class:CmsSearchIndex
Adds a parameter.- Specified by:
addConfigurationParameter
in interfaceI_CmsConfigurationParameterHandler
- Overrides:
addConfigurationParameter
in classCmsSearchIndex
- Parameters:
key
- the key/name of the parametervalue
- the value of the parameter- See Also:
-
createEmptyDocument
Description copied from class:CmsSearchIndex
Creates an empty document that can be used by this search field configuration.- Specified by:
createEmptyDocument
in interfaceI_CmsSearchIndex
- Overrides:
createEmptyDocument
in classCmsSearchIndex
- Parameters:
resource
- the resource to create the document for- Returns:
- a new and empty document
- See Also:
-
createIndexWriter
Description copied from class:CmsSearchIndex
Creates a new index writer.- Overrides:
createIndexWriter
in classCmsSearchIndex
- Parameters:
create
- iftrue
a whole new index is created, iffalse
an existing index is updatedreport
- the report- Returns:
- the created new index writer
- See Also:
-
excludeFromIndex
Description copied from class:A_CmsSearchIndex
Checks if the provided resource should be excluded from this search index.- Specified by:
excludeFromIndex
in interfaceI_CmsSearchIndex
- Overrides:
excludeFromIndex
in classA_CmsSearchIndex
- Parameters:
cms
- the OpenCms context used for building the search indexresource
- the resource to index- Returns:
- true if the resource should be excluded, false if it should be included in this index
- See Also:
-
gallerySearch
Performs a search with according to the gallery search parameters.- Parameters:
cms
- the cms contextparams
- the search parameters- Returns:
- the search result
-
getConfiguration
Description copied from class:A_CmsSearchIndex
Returns the empty configuration. Override the method if your index is configurable.- Specified by:
getConfiguration
in interfaceI_CmsConfigurationParameterHandler
- Overrides:
getConfiguration
in classCmsSearchIndex
- Returns:
- the parameters of this configurable class instance,
or
null
if the class does not need any parameters - See Also:
-
getCoreName
Returns the name of the core of the index. NOTE: Index and core name differ since OpenCms 10.5 due to new naming rules for cores in SOLR.- Returns:
- the name of the core of the index.
-
getDocument
Description copied from class:CmsSearchIndex
Returns the first document where the given term matches the selected index field.Use this method to search for documents which have unique field values, like a unique id.
- Overrides:
getDocument
in classCmsSearchIndex
- Parameters:
fieldname
- the field to search interm
- the term to search for- Returns:
- the first document where the given term matches the selected index field
- See Also:
-
getDocument
Version ofCmsSearchIndex.getDocument(java.lang.String, java.lang.String)
where the returned fields can be restricted.- Parameters:
fieldname
- the field to query interm
- the queryfls
- the returned fields.- Returns:
- the document.
-
getLocaleForResource
public Locale getLocaleForResource(CmsObject cms, CmsResource resource, List<Locale> availableLocales) Returns the language locale for the given resource in this index.- Specified by:
getLocaleForResource
in interfaceI_CmsSearchIndex
- Overrides:
getLocaleForResource
in classCmsSearchIndex
- Parameters:
cms
- the current OpenCms user contextresource
- the resource to checkavailableLocales
- a list of locales supported by the resource- Returns:
- the language locale for the given resource in this index
-
getMaxProcessedResults
Returns the maximal number of results (start + rows) that are processed for each search query unless another maximum is explicitly specified insearch(CmsObject, CmsSolrQuery, boolean, ServletResponse, boolean, CmsResourceFilter, int)
.- Returns:
- the maximal number of results (start + rows) that are processed for a search query.
-
getPostProcessor
Returns the search post processor.- Returns:
- the post processor to use
-
getServerUrl
Returns the Solr server URL to connect to for this specific index, ornull
if no specific URL is configured.- Returns:
- the Solr server URL to connect to for this specific index, or
null
if no specific URL is configured.
-
initialize
Description copied from class:A_CmsSearchIndex
Initializes the search index.- Specified by:
initialize
in interfaceI_CmsSearchIndex
- Overrides:
initialize
in classCmsSearchIndex
- Throws:
CmsSearchException
- if the index source association failed or a configuration error occurred- See Also:
-
isNoSolrServerSet
Returns a flag, indicating if the Solr server is not yet set.- Returns:
- a flag, indicating if the Solr server is not yet set.
-
search
Deprecated.Usesearch(CmsObject, SolrQuery)
orsearch(CmsObject, String)
insteadNot yet implemented for Solr.#################
### DON'T USE ###
#################
- Overrides:
search
in classCmsSearchIndex
- Parameters:
cms
- the current user's Cms objectparams
- the parameters to use for the search- Returns:
- the List of results found or an empty list
-
search
Default search method.- Parameters:
cms
- the current CMS objectquery
- the query- Returns:
- the results
- Throws:
CmsSearchException
- if something goes wrong- See Also:
-
search
public CmsSolrResultList search(CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows) throws CmsSearchException Performs a search.Returns a list of 'OpenCms resource documents' (
CmsSearchResource
) encapsulated within the classCmsSolrResultList
. This list can be accessed exactly like anList
which entries areCmsSearchResource
that extendCmsResource
and holds the Solr implementation ofI_CmsSearchDocument
as member. This enables you to deal with the resulting list as you do with well knownList
and work on it's entries like you do onCmsResource
.What will be done with the Solr search result?
- Although it can happen, that there are less results returned than rows were requested (imagine an index containing less documents than requested rows) we try to guarantee the requested amount of search results and to provide a working pagination with security check.
- To be sure we get enough documents left even the permission check reduces the amount
of found documents, the rows are multiplied by
'5'
and the current page additionally the offset is added. The count of documents we don't have enough permissions for grows with increasing page number, that's why we also multiply the rows by the current page count. - Also make sure we perform the permission check for all found documents, so start with the first found doc.
- Parameters:
cms
- the current OpenCms contextignoreMaxRows
-true
to return all all requested rows,false
to use max rowsquery
- the OpenCms Solr query- Returns:
- the list of found documents
- Throws:
CmsSearchException
- if something goes wrong- See Also:
-
search
public CmsSolrResultList search(CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows, CmsResourceFilter filter) throws CmsSearchException Likesearch(CmsObject, CmsSolrQuery, boolean)
, but additionally a resource filter can be specified. By default, the filter depends on the index.- Parameters:
cms
- the current OpenCms contextignoreMaxRows
-true
to return all all requested rows,false
to use max rowsquery
- the OpenCms Solr queryfilter
- the resource filter to use for post-processing.- Returns:
- the list of documents found.
- Throws:
CmsSearchException
- if something goes wrong
-
search
public CmsSolrResultList search(CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows, javax.servlet.ServletResponse response, boolean ignoreSearchExclude, CmsResourceFilter filter) throws CmsSearchException Performs the actual search.- Parameters:
cms
- the current OpenCms contextquery
- the OpenCms Solr queryignoreMaxRows
-true
to return all all requested rows,false
to use max rowsresponse
- the servlet response to write the query result to, may also benull
ignoreSearchExclude
- if set to false, only contents with search_exclude unset or "false" will be found - typical for the the non-gallery casefilter
- the resource filter to use- Returns:
- the found documents
- Throws:
CmsSearchException
- if something goes wrong- See Also:
-
search
public CmsSolrResultList search(CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows, javax.servlet.ServletResponse response, boolean ignoreSearchExclude, CmsResourceFilter filter, int maxNumResults) throws CmsSearchException Performs the actual search.To provide for correct permissions two queries are performed and the response is fused from that queries:
- a query for permission checking, where fl, start and rows is adjusted. From this query result we take for the response:
- facets
- spellcheck
- suggester
- morelikethis
- clusters
- a query that collects only the resources determined by the first query and performs highlighting. From this query we take for the response:
- result
- highlighting
- groups
- collapse - representatives of the collapsed group might be filtered by the permission check
- expand is disabled
- Parameters:
cms
- the current OpenCms contextquery
- the OpenCms Solr queryignoreMaxRows
-true
to return all requested rows,false
to use max rowsresponse
- the servlet response to write the query result to, may also benull
ignoreSearchExclude
- if set to false, only contents with search_exclude unset or "false" will be found - typical for the the non-gallery casefilter
- the resource filter to usemaxNumResults
- the maximal number of results to search for- Returns:
- the found documents
- Throws:
CmsSearchException
- if something goes wrong- See Also:
- a query for permission checking, where fl, start and rows is adjusted. From this query result we take for the response:
-
search
public CmsSolrResultList search(CmsObject cms, org.apache.solr.client.solrj.SolrQuery query) throws CmsSearchException Default search method.- Parameters:
cms
- the current CMS objectquery
- the query- Returns:
- the results
- Throws:
CmsSearchException
- if something goes wrong- See Also:
-
search
Performs a search.- Parameters:
cms
- the cms objectsolrQuery
- the Solr query- Returns:
- a list of documents
- Throws:
CmsSearchException
- if something goes wrong- See Also:
-
select
public void select(javax.servlet.ServletResponse response, CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows) throws Exception Writes the response into the writer.NOTE: Currently not available for HTTP server.
- Parameters:
response
- the servlet responsecms
- the CMS object to use for searchquery
- the Solr queryignoreMaxRows
- if to return unlimited results- Throws:
Exception
- if there is no embedded server
-
setName
Sets the logical key/name of this search index.- Specified by:
setName
in interfaceI_CmsSearchIndex
- Overrides:
setName
in classA_CmsSearchIndex
- Parameters:
name
- the logical key/name of this search index- Throws:
CmsIllegalArgumentException
- if the given name is null, empty or already taken by another search index- See Also:
-
setPostProcessor
Sets the search post processor.- Parameters:
postProcessor
- the search post processor to set
-
setSolrServer
Sets the Solr server used by this index.- Parameters:
client
- the server to set
-
spellCheck
public void spellCheck(javax.servlet.ServletResponse res, CmsObject cms, CmsSolrQuery q) throws CmsSearchException Executes a spell checking Solr query and returns the Solr query response.- Parameters:
res
- the servlet responsecms
- the CMS objectq
- the query- Throws:
CmsSearchException
- if something goes wrong
-
createIndexBackup
Description copied from class:CmsSearchIndex
Creates a backup of this index for optimized re-indexing of the whole content.- Overrides:
createIndexBackup
in classCmsSearchIndex
- Returns:
- the path to the backup folder, or
null
in case no backup was created - See Also:
-
hasPermissions
Check, if the current user has permissions on the document's resource.- Parameters:
cms
- the contextdoc
- the solr document (from the search result)filter
- the resource filter to use for checking permissions- Returns:
true
iff the resource mirrored by the search result can be read by the current user.
-
indexSearcherClose
Description copied from class:CmsSearchIndex
Closes the index searcher for this index.- Overrides:
indexSearcherClose
in classCmsSearchIndex
- See Also:
-
indexSearcherOpen
Description copied from class:CmsSearchIndex
Initializes the index searcher for this index.In case there is an index searcher still open, it is closed first.
For performance reasons, one instance of the index searcher should be kept for all searches. However, if the index is updated or changed this searcher instance needs to be re-initialized.
- Overrides:
indexSearcherOpen
in classCmsSearchIndex
- Parameters:
path
- the path to the index directory- See Also:
-
indexSearcherUpdate
Description copied from class:CmsSearchIndex
Reopens the index search reader for this index, required after the index has been changed.- Overrides:
indexSearcherUpdate
in classCmsSearchIndex
- See Also:
-
search(CmsObject, SolrQuery)
orsearch(CmsObject, String)
instead