org.opencms.search.solr
Class CmsSolrIndex

java.lang.Object
  extended by org.opencms.search.CmsSearchIndex
      extended by org.opencms.search.solr.CmsSolrIndex
All Implemented Interfaces:
I_CmsConfigurationParameterHandler

public class CmsSolrIndex
extends CmsSearchIndex

Implements the search within an Solr index.

Since:
8.5.0

Nested Class Summary
 
Nested classes/interfaces inherited from class org.opencms.search.CmsSearchIndex
CmsSearchIndex.LazyContentReader
 
Field Summary
protected static int DEBUG_PADDING_RIGHT
          A constant for debug formatting outpu.
static java.lang.String DEFAULT_INDEX_NAME_OFFLINE
          The name of the default Solr Offline index.
static java.lang.String DEFAULT_INDEX_NAME_ONLINE
          The name of the default Solr Online index.
static java.lang.String POST_PROCESSOR
          Constant for additional parameter to set the post processor class name.
static java.lang.String PROPERTY_SEARCH_EXCLUDE_VALUE_SOLR
          The solr exclude property.
 
Fields inherited from class org.opencms.search.CmsSearchIndex
A_LEGACY_PARAM_PREFIX, BACKUP_REINDEXING, DATES, DOC_META_FIELDS, EXCERPT, EXTRACT_CONTENT, LANGUAGEDETECTION, LUCENE_AUTO_COMMIT, LUCENE_MAX_MERGE_DOCS, LUCENE_MERGE_FACTOR, LUCENE_RAM_BUFFER_SIZE_MB, LUCENE_USE_COMPOUND_FILE, LUCENE_VERSION, MAX_HITS, MAX_HITS_DEFAULT, MAX_YEAR_RANGE, PERMISSIONS, PRIORITY, PROPERTY_SEARCH_EXCLUDE_VALUE_ALL, PROPERTY_SEARCH_EXCLUDE_VALUE_GALLERY, REBUILD_MODE_AUTO, REBUILD_MODE_MANUAL, REBUILD_MODE_OFFLINE, TIME_RANGE, TYPE_XMLCONTENT, USE_ALL_LOCALE
 
Fields inherited from interface org.opencms.configuration.I_CmsConfigurationParameterHandler
ADD_PARAMETER_METHOD, INIT_CONFIGURATION_METHOD
 
Constructor Summary
CmsSolrIndex()
          Default constructor.
CmsSolrIndex(java.lang.String name)
          Public constructor to create a Solr index.
 
Method Summary
 void addConfigurationParameter(java.lang.String key, java.lang.String value)
          Adds a parameter.
 I_CmsSearchDocument createEmptyDocument(CmsResource resource)
          Creates an empty document that can be used by this search field configuration.
protected  java.lang.String createIndexBackup()
          Creates a backup of this index for optimized re-indexing of the whole content.
 I_CmsIndexWriter createIndexWriter(boolean create, I_CmsReport report)
          Creates a new index writer.
protected  boolean excludeFromIndex(CmsObject cms, CmsResource resource)
          Checks if the provided resource should be excluded from this search index.
 CmsParameterConfiguration getConfiguration()
          Returns the parameters of this configurable class instance, or null if the class does not need any parameters.
 I_CmsSearchDocument getDocument(java.lang.String fieldname, java.lang.String term)
          Returns the first document where the given term matches the selected index field.
 I_CmsDocumentFactory getDocumentFactory(CmsResource res)
          Returns the document type factory used for the given resource in this index, or null in case the resource is not indexed by this index.
 java.util.Locale getLocaleForResource(CmsObject cms, CmsResource resource, java.util.List<java.util.Locale> availableLocales)
          Returns the language locale for the given resource in this index.
 I_CmsSolrPostSearchProcessor getPostProcessor()
          Returns the search post processor.
static java.lang.String getType(CmsObject cms, java.lang.String rootPath)
          Returns the resource type for the given root path.
protected  void indexSearcherClose()
          Closes the index searcher for this index.
protected  void indexSearcherOpen(java.lang.String path)
          Initializes the index searcher for this index.
protected  void indexSearcherUpdate()
          Reopens the index search reader for this index, required after the index has been changed.
 void initialize()
          Initializes the search index.
protected  boolean isIndexing(CmsResource res)
          Checks if the given resource should be indexed by this index or not.
 CmsSearchResultList search(CmsObject cms, CmsSearchParameters params)
          Deprecated. 
 CmsSolrResultList search(CmsObject cms, CmsSolrQuery query)
          Default search method.
 CmsSolrResultList search(CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows)
          Performs a search on the Solr index Returns a list of 'OpenCms resource documents' (CmsSearchResource) encapsulated within the class CmsSolrResultList.
 CmsSolrResultList search(CmsObject cms, org.apache.solr.client.solrj.SolrQuery query)
          Default search method.
 CmsSolrResultList search(CmsObject cms, java.lang.String solrQuery)
          Performs a search.
 void select(javax.servlet.ServletResponse response, CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows)
          Writes the response into the writer.
 void setPostProcessor(I_CmsSolrPostSearchProcessor postProcessor)
          Sets the search post processor.
 void shutDown()
          Shuts down the search index.
 
Methods inherited from class org.opencms.search.CmsSearchIndex
addSourceName, appendCategoryFilter, appendDateCreatedFilter, appendDateLastModifiedFilter, appendPathFilter, appendResourceTypeFilter, checkConfiguration, createDateRangeFilter, equals, extendPathFilter, generateIndexDirectory, getAnalyzer, getDateRangeSpan, getDocument, getFieldConfiguration, getFieldConfigurationName, getFieldSelector, getIndexWriter, getLocale, getLocaleString, getMaxHits, getMultiTermQueryFilter, getMultiTermQueryFilter, getMultiTermQueryFilter, getName, getPath, getPriority, getProject, getRebuildMode, getResource, getSearcher, getSourceNames, getSources, getTermQueryFilter, hashCode, hasReadPermission, indexSearcherClose, indexWriterUnlock, initConfiguration, isBackupReindexing, isCheckingPermissions, isCheckingTimeRange, isCheckPermissions, isCreatingExcerpt, isEnabled, isExtractingContent, isInTimeRange, isLanguageDetection, isRequireViewPermission, isUpdatedIncremental, needsPermissionCheck, prepareSortScoring, removeIndexBackup, removeSourceName, setAnalyzer, setCheckPermissions, setEnabled, setFieldConfiguration, setFieldConfigurationName, setIndexWriter, setLanguageDetection, setLocale, setLocaleString, setMaxHits, setName, setProject, setRebuildMode, setRequireViewPermission, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_INDEX_NAME_OFFLINE

public static final java.lang.String DEFAULT_INDEX_NAME_OFFLINE
The name of the default Solr Offline index.

See Also:
Constant Field Values

DEFAULT_INDEX_NAME_ONLINE

public static final java.lang.String DEFAULT_INDEX_NAME_ONLINE
The name of the default Solr Online index.

See Also:
Constant Field Values

POST_PROCESSOR

public static final java.lang.String POST_PROCESSOR
Constant for additional parameter to set the post processor class name.

See Also:
Constant Field Values

PROPERTY_SEARCH_EXCLUDE_VALUE_SOLR

public static final java.lang.String PROPERTY_SEARCH_EXCLUDE_VALUE_SOLR
The solr exclude property.

See Also:
Constant Field Values

DEBUG_PADDING_RIGHT

protected static final int DEBUG_PADDING_RIGHT
A constant for debug formatting outpu.

See Also:
Constant Field Values
Constructor Detail

CmsSolrIndex

public CmsSolrIndex()
Default constructor.


CmsSolrIndex

public CmsSolrIndex(java.lang.String name)
             throws CmsIllegalArgumentException
Public constructor to create a Solr index.

Parameters:
name - the name for this index.

Throws:
CmsIllegalArgumentException - if something goes wrong
Method Detail

getType

public static final java.lang.String getType(CmsObject cms,
                                             java.lang.String rootPath)
Returns the resource type for the given root path.

Parameters:
cms - the current CMS context
rootPath - the root path of the resource to get the type for
Returns:
the resource type for the given root path

addConfigurationParameter

public void addConfigurationParameter(java.lang.String key,
                                      java.lang.String value)
Description copied from class: CmsSearchIndex
Adds a parameter.

Specified by:
addConfigurationParameter in interface I_CmsConfigurationParameterHandler
Overrides:
addConfigurationParameter in class CmsSearchIndex
Parameters:
key - the key/name of the parameter
value - the value of the parameter
See Also:
CmsSearchIndex.addConfigurationParameter(java.lang.String, java.lang.String)

createEmptyDocument

public I_CmsSearchDocument createEmptyDocument(CmsResource resource)
Description copied from class: CmsSearchIndex
Creates an empty document that can be used by this search field configuration.

Overrides:
createEmptyDocument in class CmsSearchIndex
Parameters:
resource - the resource to create the document for
Returns:
a new and empty document
See Also:
CmsSearchIndex.createEmptyDocument(org.opencms.file.CmsResource)

createIndexWriter

public I_CmsIndexWriter createIndexWriter(boolean create,
                                          I_CmsReport report)
Description copied from class: CmsSearchIndex
Creates a new index writer.

Overrides:
createIndexWriter in class CmsSearchIndex
Parameters:
create - if true a whole new index is created, if false an existing index is updated
report - the report
Returns:
the created new index writer
See Also:
CmsSearchIndex.createIndexWriter(boolean, org.opencms.report.I_CmsReport)

getConfiguration

public CmsParameterConfiguration getConfiguration()
Description copied from interface: I_CmsConfigurationParameterHandler
Returns the parameters of this configurable class instance, or null if the class does not need any parameters.

Specified by:
getConfiguration in interface I_CmsConfigurationParameterHandler
Overrides:
getConfiguration in class CmsSearchIndex
Returns:
the parameters of this configurable class instance, or null if the class does not need any parameters
See Also:
CmsSearchIndex.getConfiguration()

getDocument

public I_CmsSearchDocument getDocument(java.lang.String fieldname,
                                       java.lang.String term)
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 class CmsSearchIndex
Parameters:
fieldname - the field to search in
term - the term to search for
Returns:
the first document where the given term matches the selected index field
See Also:
CmsSearchIndex.getDocument(java.lang.String, java.lang.String)

getDocumentFactory

public I_CmsDocumentFactory getDocumentFactory(CmsResource res)
Description copied from class: CmsSearchIndex
Returns the document type factory used for the given resource in this index, or null in case the resource is not indexed by this index.

A resource is indexed if the following is all true:

  1. The index contains at last one index source matching the root path of the given resource.
  2. For this matching index source, the document type factory needed by the resource is also configured.

Overrides:
getDocumentFactory in class CmsSearchIndex
Parameters:
res - the resource to check
Returns:
he document type factory used for the given resource in this index, or null in case the resource is not indexed by this index
See Also:
CmsSearchIndex.getDocumentFactory(org.opencms.file.CmsResource)

getLocaleForResource

public java.util.Locale getLocaleForResource(CmsObject cms,
                                             CmsResource resource,
                                             java.util.List<java.util.Locale> availableLocales)
Returns the language locale for the given resource in this index.

Overrides:
getLocaleForResource in class CmsSearchIndex
Parameters:
cms - the current OpenCms user context
resource - the resource to check
availableLocales - a list of locales supported by the resource
Returns:
the language locale for the given resource in this index

getPostProcessor

public I_CmsSolrPostSearchProcessor getPostProcessor()
Returns the search post processor.

Returns:
the post processor to use

initialize

public void initialize()
                throws CmsSearchException
Description copied from class: CmsSearchIndex
Initializes the search index.

Overrides:
initialize in class CmsSearchIndex
Throws:
CmsSearchException - if the index source association failed or a configuration error occurred
See Also:
CmsSearchIndex.initialize()

search

@Deprecated
public CmsSearchResultList search(CmsObject cms,
                                             CmsSearchParameters params)
Deprecated. 

Not yet implemented for Solr.

#################
### DON'T USE ###
#################

Overrides:
search in class CmsSearchIndex
Parameters:
cms - the current user's Cms object
params - the parameters to use for the search
Returns:
the List of results found or an empty list

search

public CmsSolrResultList search(CmsObject cms,
                                CmsSolrQuery query)
                         throws CmsSearchException
Default search method.

Parameters:
cms - the current CMS object
query - the query
Returns:
the results
Throws:
CmsSearchException - if something goes wrong
See Also:
search(CmsObject, String)

search

public CmsSolrResultList search(CmsObject cms,
                                CmsSolrQuery query,
                                boolean ignoreMaxRows)
                         throws CmsSearchException

Performs a search on the Solr index

Returns a list of 'OpenCms resource documents' (CmsSearchResource) encapsulated within the class CmsSolrResultList. This list can be accessed exactly like an List which entries are CmsSearchResource that extend CmsResource and holds the Solr implementation of I_CmsSearchDocument as member. This enables you to deal with the resulting list as you do with well known List and work on it's entries like you do on CmsResource.

What will be done with the Solr search result?

NOTE: If latter pages than the current one are containing protected documents the total hit count will be incorrect, because the permission check ends if we have enough results found for the page to display. With other words latter pages than the current can contain documents that will first be checked if those pages are requested to be displayed, what causes a incorrect hit count.

Parameters:
cms - the current OpenCms context
ignoreMaxRows - true to return all all requested rows, false to use max rows
query - the OpenCms Solr query
Returns:
the list of found documents
Throws:
CmsSearchException - if something goes wrong
See Also:
CmsSolrResultList, CmsSearchResource, I_CmsSearchDocument, CmsSolrQuery

search

public CmsSolrResultList search(CmsObject cms,
                                org.apache.solr.client.solrj.SolrQuery query)
                         throws CmsSearchException
Default search method.

Parameters:
cms - the current CMS object
query - the query
Returns:
the results
Throws:
CmsSearchException - if something goes wrong
See Also:
search(CmsObject, String)

search

public CmsSolrResultList search(CmsObject cms,
                                java.lang.String solrQuery)
                         throws CmsSearchException
Performs a search.

Parameters:
cms - the cms object
solrQuery - the Solr query
Returns:
a list of documents
Throws:
CmsSearchException - if something goes wrong
See Also:
search(CmsObject, CmsSolrQuery, boolean)

select

public void select(javax.servlet.ServletResponse response,
                   CmsObject cms,
                   CmsSolrQuery query,
                   boolean ignoreMaxRows)
            throws java.lang.Exception
Writes the response into the writer.

NOTE: Currently not available for HTTP server.

Parameters:
response - the servlet response
cms - the CMS object to use for search
query - the Solr query
ignoreMaxRows - if to return unlimited results
Throws:
java.lang.Exception - if there is no embedded server

setPostProcessor

public void setPostProcessor(I_CmsSolrPostSearchProcessor postProcessor)
Sets the search post processor.

Parameters:
postProcessor - the search post processor to set

shutDown

public void shutDown()
Description copied from class: CmsSearchIndex
Shuts down the search index.

This will close the local Lucene index searcher instance.

Overrides:
shutDown in class CmsSearchIndex
See Also:
CmsSearchIndex.shutDown()

createIndexBackup

protected java.lang.String createIndexBackup()
Description copied from class: CmsSearchIndex
Creates a backup of this index for optimized re-indexing of the whole content.

Overrides:
createIndexBackup in class CmsSearchIndex
Returns:
the path to the backup folder, or null in case no backup was created
See Also:
CmsSearchIndex.createIndexBackup()

excludeFromIndex

protected boolean excludeFromIndex(CmsObject cms,
                                   CmsResource resource)
Description copied from class: CmsSearchIndex
Checks if the provided resource should be excluded from this search index.

Overrides:
excludeFromIndex in class CmsSearchIndex
Parameters:
cms - the OpenCms context used for building the search index
resource - the resource to index
Returns:
true if the resource should be excluded, false if it should be included in this index
See Also:
CmsSearchIndex.excludeFromIndex(CmsObject, CmsResource)

indexSearcherClose

protected void indexSearcherClose()
Description copied from class: CmsSearchIndex
Closes the index searcher for this index.

Overrides:
indexSearcherClose in class CmsSearchIndex
See Also:
CmsSearchIndex.indexSearcherClose()

indexSearcherOpen

protected void indexSearcherOpen(java.lang.String path)
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 class CmsSearchIndex
Parameters:
path - the path to the index directory
See Also:
CmsSearchIndex.indexSearcherOpen(java.lang.String)

indexSearcherUpdate

protected void indexSearcherUpdate()
Description copied from class: CmsSearchIndex
Reopens the index search reader for this index, required after the index has been changed.

Overrides:
indexSearcherUpdate in class CmsSearchIndex
See Also:
CmsSearchIndex.indexSearcherUpdate()

isIndexing

protected boolean isIndexing(CmsResource res)
Checks if the given resource should be indexed by this index or not.

Parameters:
res - the resource candidate
Returns:
true if the given resource should be indexed or false if not