Class CmsSolrIndex
- All Implemented Interfaces:
Serializable,I_CmsConfigurationParameterHandler,I_CmsSearchIndex
- Since:
- 8.5.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intA constant for debug formatting output.static final StringThe name of the default Solr Offline index.static final StringThe name of the default Solr Online index.static final intThe constant for an unlimited maximum number of results to return in a Solr search.static final intThe constant for an unlimited maximum number of results to return in a Solr search.static final StringConstant for additional parameter to set the post processor class name.static final StringThe solr exclude property.static final intIndicates the maximum number of documents from the complete result set to return.static final StringConstant for additional parameter to set the fields the select handler should return at maximum.static final StringConstant for additional parameter to set the maximal number of a result, the select handler should return.static final StringConstant for additional parameter to set the number results the select handler should return at maxium per request.static final StringConstant 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, VISITORFields inherited from class org.opencms.search.A_CmsSearchIndex
PROPERTY_SEARCH_EXCLUDE_VALUE_ALL, PROPERTY_SEARCH_EXCLUDE_VALUE_GALLERY, USE_ALL_LOCALEFields inherited from interface org.opencms.configuration.I_CmsConfigurationParameterHandler
ADD_PARAMETER_METHOD, INIT_CONFIGURATION_METHODFields inherited from interface org.opencms.search.I_CmsSearchIndex
REBUILD_MODE_AUTO, REBUILD_MODE_MANUAL, REBUILD_MODE_NEVER, REBUILD_MODE_OFFLINE -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.CmsSolrIndex(String name) Public constructor to create a Solr index. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConfigurationParameter(String key, String value) Adds a parameter.createEmptyDocument(CmsResource resource) Creates an empty document that can be used by this search field configuration.protected StringCreates a backup of this index for optimized re-indexing of the whole content.createIndexWriter(boolean create, I_CmsReport report) Creates a new index writer.booleanexcludeFromIndex(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.intReturns 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, ornullif no specific URL is configured.static final StringReturns the resource type for the given root path.protected booleanhasPermissions(CmsObject cms, CmsSolrDocument doc, CmsResourceFilter filter) Check, if the current user has permissions on the document's resource.protected voidCloses the index searcher for this index.protected voidindexSearcherOpen(String path) Initializes the index searcher for this index.protected voidReopens the index search reader for this index, required after the index has been changed.voidInitializes the search index.booleanReturns 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.voidselect(javax.servlet.ServletResponse response, CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows) Writes the response into the writer.voidSets the logical key/name of this search index.voidsetPostProcessor(I_CmsSolrPostSearchProcessor postProcessor) Sets the search post processor.voidsetSolrServer(org.apache.solr.client.solrj.SolrClient client) Sets the Solr server used by this index.voidspellCheck(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, toStringMethods 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:CmsSearchIndexAdds a parameter.- Specified by:
addConfigurationParameterin interfaceI_CmsConfigurationParameterHandler- Overrides:
addConfigurationParameterin classCmsSearchIndex- Parameters:
key- the key/name of the parametervalue- the value of the parameter- See Also:
-
createEmptyDocument
Description copied from class:CmsSearchIndexCreates an empty document that can be used by this search field configuration.- Specified by:
createEmptyDocumentin interfaceI_CmsSearchIndex- Overrides:
createEmptyDocumentin classCmsSearchIndex- Parameters:
resource- the resource to create the document for- Returns:
- a new and empty document
- See Also:
-
createIndexWriter
Description copied from class:CmsSearchIndexCreates a new index writer.- Overrides:
createIndexWriterin classCmsSearchIndex- Parameters:
create- iftruea whole new index is created, iffalsean existing index is updatedreport- the report- Returns:
- the created new index writer
- See Also:
-
excludeFromIndex
Description copied from class:A_CmsSearchIndexChecks if the provided resource should be excluded from this search index.- Specified by:
excludeFromIndexin interfaceI_CmsSearchIndex- Overrides:
excludeFromIndexin 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_CmsSearchIndexReturns the empty configuration. Override the method if your index is configurable.- Specified by:
getConfigurationin interfaceI_CmsConfigurationParameterHandler- Overrides:
getConfigurationin classCmsSearchIndex- Returns:
- the parameters of this configurable class instance,
or
nullif 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:CmsSearchIndexReturns 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:
getDocumentin 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:
getLocaleForResourcein interfaceI_CmsSearchIndex- Overrides:
getLocaleForResourcein 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, ornullif no specific URL is configured.- Returns:
- the Solr server URL to connect to for this specific index, or
nullif no specific URL is configured.
-
initialize
Description copied from class:A_CmsSearchIndexInitializes the search index.- Specified by:
initializein interfaceI_CmsSearchIndex- Overrides:
initializein 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:
searchin 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 anListwhich entries areCmsSearchResourcethat extendCmsResourceand holds the Solr implementation ofI_CmsSearchDocumentas member. This enables you to deal with the resulting list as you do with well knownListand 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 contextquery- the OpenCms Solr queryignoreMaxRows-trueto return all all requested rows,falseto use max rows- 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 contextquery- the OpenCms Solr queryignoreMaxRows-trueto return all all requested rows,falseto use max rowsfilter- 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-trueto return all all requested rows,falseto use max rowsresponse- the servlet response to write the query result to, may also benullignoreSearchExclude- 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-trueto return all requested rows,falseto use max rowsresponse- the servlet response to write the query result to, may also benullignoreSearchExclude- 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:
setNamein interfaceI_CmsSearchIndex- Overrides:
setNamein 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:CmsSearchIndexCreates a backup of this index for optimized re-indexing of the whole content.- Overrides:
createIndexBackupin classCmsSearchIndex- Returns:
- the path to the backup folder, or
nullin 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:
trueiff the resource mirrored by the search result can be read by the current user.
-
indexSearcherClose
Description copied from class:CmsSearchIndexCloses the index searcher for this index.- Overrides:
indexSearcherClosein classCmsSearchIndex- See Also:
-
indexSearcherOpen
Description copied from class:CmsSearchIndexInitializes 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:
indexSearcherOpenin classCmsSearchIndex- Parameters:
path- the path to the index directory- See Also:
-
indexSearcherUpdate
Description copied from class:CmsSearchIndexReopens the index search reader for this index, required after the index has been changed.- Overrides:
indexSearcherUpdatein classCmsSearchIndex- See Also:
-
search(CmsObject, SolrQuery)orsearch(CmsObject, String)instead