public class CmsSolrIndex extends CmsSearchIndex
| Modifier and Type | Field and Description |
|---|---|
protected static int |
DEBUG_PADDING_RIGHT
A constant for debug formatting output.
|
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 int |
MAX_RESULTS_GALLERY
The constant for an unlimited maximum number of results to return in a Solr search.
|
static int |
MAX_RESULTS_UNLIMITED
The constant for an unlimited maximum number of results to return in a Solr search.
|
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.
|
static int |
ROWS_MAX
Indicates the maximum number of documents from the complete result set to return.
|
static java.lang.String |
SOLR_HANDLER_ALLOWED_FIELDS
Constant for additional parameter to set the fields the select handler should return at maximum.
|
static java.lang.String |
SOLR_HANDLER_MAX_ALLOWED_RESULTS_AT_ALL
Constant for additional parameter to set the maximal number of a result, the select handler should return.
|
static java.lang.String |
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.
|
static java.lang.String |
SOLR_SEARCH_MAX_PROCESSED_RESULTS
Constant for additional parameter to set the maximally processed results (start + rows) for searches with this index.
|
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, TYPE_XMLCONTENT, VISITORPROPERTY_SEARCH_EXCLUDE_VALUE_ALL, PROPERTY_SEARCH_EXCLUDE_VALUE_GALLERY, USE_ALL_LOCALEREBUILD_MODE_AUTO, REBUILD_MODE_MANUAL, REBUILD_MODE_NEVER, REBUILD_MODE_OFFLINEADD_PARAMETER_METHOD, INIT_CONFIGURATION_METHOD| Constructor and Description |
|---|
CmsSolrIndex()
Default constructor.
|
CmsSolrIndex(java.lang.String name)
Public constructor to create a Solr index.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
boolean |
excludeFromIndex(CmsObject cms,
CmsResource resource)
Checks if the provided resource should be excluded from this search index.
|
CmsGallerySearchResultList |
gallerySearch(CmsObject cms,
CmsGallerySearchParameters params)
Performs a search with according to the gallery search parameters.
|
CmsParameterConfiguration |
getConfiguration()
Returns the empty configuration.
|
java.lang.String |
getCoreName()
Returns the name of the core of the index.
|
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_CmsSearchDocument |
getDocument(java.lang.String fieldname,
java.lang.String term,
java.lang.String[] fls)
Version of
CmsSearchIndex.getDocument(java.lang.String, java.lang.String) where
the returned fields can be restricted. |
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.
|
int |
getMaxProcessedResults()
Returns the maximal number of results (start + rows) that are processed for each search query unless another
maximum is explicitly specified in
search(CmsObject, CmsSolrQuery, boolean, ServletResponse, boolean, CmsResourceFilter, int). |
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 boolean |
hasPermissions(CmsObject cms,
CmsSolrDocument doc,
CmsResourceFilter filter)
Check, if the current user has permissions on the document's resource.
|
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.
|
boolean |
isNoSolrServerSet()
Returns a flag, indicating if the Solr server is not yet set.
|
CmsSearchResultList |
search(CmsObject cms,
CmsSearchParameters params)
Deprecated.
Use
search(CmsObject, SolrQuery) or search(CmsObject, String) instead |
CmsSolrResultList |
search(CmsObject cms,
CmsSolrQuery query)
Default search method.
|
CmsSolrResultList |
search(CmsObject cms,
CmsSolrQuery query,
boolean ignoreMaxRows)
Performs a search.
|
CmsSolrResultList |
search(CmsObject cms,
CmsSolrQuery query,
boolean ignoreMaxRows,
CmsResourceFilter filter)
Like
search(CmsObject, CmsSolrQuery, boolean), but additionally a resource filter can be specified. |
CmsSolrResultList |
search(CmsObject cms,
CmsSolrQuery query,
boolean ignoreMaxRows,
javax.servlet.ServletResponse response,
boolean ignoreSearchExclude,
CmsResourceFilter filter)
Performs the actual search.
|
CmsSolrResultList |
search(CmsObject cms,
CmsSolrQuery query,
boolean ignoreMaxRows,
javax.servlet.ServletResponse response,
boolean ignoreSearchExclude,
CmsResourceFilter filter,
int maxNumResults)
Performs the actual search.
|
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 |
setName(java.lang.String name)
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.
|
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, toStringaddSourceName, checkConfiguration, equals, getFieldConfiguration, getFieldConfigurationName, getIndexWriter, getLocale, getName, getProject, getRebuildMode, getSourceNames, getSources, hashCode, initConfiguration, isEnabled, isExtractingContent, isLanguageDetection, isUpdatedIncremental, removeSourceName, setEnabled, setExtractContent, setFieldConfiguration, setFieldConfigurationName, setIndexWriter, setLanguageDetection, setLocale, setLocaleString, setPath, setProject, setRebuildModepublic static final java.lang.String DEFAULT_INDEX_NAME_OFFLINE
public static final java.lang.String DEFAULT_INDEX_NAME_ONLINE
public static final java.lang.String POST_PROCESSOR
public static final java.lang.String SOLR_SEARCH_MAX_PROCESSED_RESULTS
CmsSolrConfiguration.getMaxProcessedResults() for this index.public static final java.lang.String SOLR_HANDLER_ALLOWED_FIELDS
public static final java.lang.String SOLR_HANDLER_MAX_ALLOWED_RESULTS_PER_PAGE
public static final java.lang.String SOLR_HANDLER_MAX_ALLOWED_RESULTS_AT_ALL
public static final java.lang.String PROPERTY_SEARCH_EXCLUDE_VALUE_SOLR
public static final int ROWS_MAX
public static final int MAX_RESULTS_UNLIMITED
public static final int MAX_RESULTS_GALLERY
protected static final int DEBUG_PADDING_RIGHT
public CmsSolrIndex()
public CmsSolrIndex(java.lang.String name) throws CmsIllegalArgumentException
name - the name for this index.CmsIllegalArgumentException - if something goes wrongpublic static final java.lang.String getType(CmsObject cms, java.lang.String rootPath)
cms - the current CMS contextrootPath - the root path of the resource to get the type forpublic void addConfigurationParameter(java.lang.String key, java.lang.String value)
CmsSearchIndexaddConfigurationParameter in interface I_CmsConfigurationParameterHandleraddConfigurationParameter in class CmsSearchIndexkey - the key/name of the parametervalue - the value of the parameterCmsSearchIndex.addConfigurationParameter(java.lang.String, java.lang.String)public I_CmsSearchDocument createEmptyDocument(CmsResource resource)
CmsSearchIndexcreateEmptyDocument in interface I_CmsSearchIndexcreateEmptyDocument in class CmsSearchIndexresource - the resource to create the document forCmsSearchIndex.createEmptyDocument(org.opencms.file.CmsResource)public I_CmsIndexWriter createIndexWriter(boolean create, I_CmsReport report)
CmsSearchIndexcreateIndexWriter in class CmsSearchIndexcreate - if true a whole new index is created, if false an existing index is updatedreport - the reportCmsSearchIndex.createIndexWriter(boolean, org.opencms.report.I_CmsReport)public boolean excludeFromIndex(CmsObject cms, CmsResource resource)
A_CmsSearchIndexexcludeFromIndex in interface I_CmsSearchIndexexcludeFromIndex in class A_CmsSearchIndexcms - the OpenCms context used for building the search indexresource - the resource to indexA_CmsSearchIndex.excludeFromIndex(CmsObject, CmsResource)public CmsGallerySearchResultList gallerySearch(CmsObject cms, CmsGallerySearchParameters params)
cms - the cms contextparams - the search parameterspublic CmsParameterConfiguration getConfiguration()
A_CmsSearchIndexgetConfiguration in interface I_CmsConfigurationParameterHandlergetConfiguration in class CmsSearchIndexnull if the class does not need any parametersCmsSearchIndex.getConfiguration()public java.lang.String getCoreName()
public I_CmsSearchDocument getDocument(java.lang.String fieldname, java.lang.String term)
CmsSearchIndexUse this method to search for documents which have unique field values, like a unique id.
getDocument in class CmsSearchIndexfieldname - the field to search interm - the term to search forCmsSearchIndex.getDocument(java.lang.String, java.lang.String)public I_CmsSearchDocument getDocument(java.lang.String fieldname, java.lang.String term, java.lang.String[] fls)
CmsSearchIndex.getDocument(java.lang.String, java.lang.String) where
the returned fields can be restricted.fieldname - the field to query interm - the queryfls - the returned fields.public I_CmsDocumentFactory getDocumentFactory(CmsResource res)
CmsSearchIndexnull
in case the resource is not indexed by this index.A resource is indexed if the following is all true:
getDocumentFactory in interface I_CmsSearchIndexgetDocumentFactory in class CmsSearchIndexres - the resource to checknull
in case the resource is not indexed by this indexCmsSearchIndex.getDocumentFactory(org.opencms.file.CmsResource)public java.util.Locale getLocaleForResource(CmsObject cms, CmsResource resource, java.util.List<java.util.Locale> availableLocales)
getLocaleForResource in interface I_CmsSearchIndexgetLocaleForResource in class CmsSearchIndexcms - the current OpenCms user contextresource - the resource to checkavailableLocales - a list of locales supported by the resourcepublic int getMaxProcessedResults()
search(CmsObject, CmsSolrQuery, boolean, ServletResponse, boolean, CmsResourceFilter, int).public I_CmsSolrPostSearchProcessor getPostProcessor()
public void initialize() throws CmsSearchException
A_CmsSearchIndexinitialize in interface I_CmsSearchIndexinitialize in class CmsSearchIndexCmsSearchException - if the index source association failed or a configuration error occurredCmsSearchIndex.initialize()public boolean isNoSolrServerSet()
@Deprecated public CmsSearchResultList search(CmsObject cms, CmsSearchParameters params)
search(CmsObject, SolrQuery) or search(CmsObject, String) instead
#################
### DON'T USE ###
#################
search in class CmsSearchIndexcms - the current user's Cms objectparams - the parameters to use for the searchpublic CmsSolrResultList search(CmsObject cms, CmsSolrQuery query) throws CmsSearchException
cms - the current CMS objectquery - the queryCmsSearchException - if something goes wrongsearch(CmsObject, String)public CmsSolrResultList search(CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows) throws CmsSearchException
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.
'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.cms - the current OpenCms contextignoreMaxRows - true to return all all requested rows, false to use max rowsquery - the OpenCms Solr queryCmsSearchException - if something goes wrongCmsSolrResultList,
CmsSearchResource,
I_CmsSearchDocument,
CmsSolrQuerypublic CmsSolrResultList search(CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows, CmsResourceFilter filter) throws CmsSearchException
search(CmsObject, CmsSolrQuery, boolean), but additionally a resource filter can be specified.
By default, the filter depends on the index.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.CmsSearchException - if something goes wrongpublic CmsSolrResultList search(CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows, javax.servlet.ServletResponse response, boolean ignoreSearchExclude, CmsResourceFilter filter) throws CmsSearchException
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 be nullignoreSearchExclude - 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 useCmsSearchException - if something goes wrongsearch(CmsObject, CmsSolrQuery, boolean)public CmsSolrResultList search(CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows, javax.servlet.ServletResponse response, boolean ignoreSearchExclude, CmsResourceFilter filter, int maxNumResults) throws CmsSearchException
To provide for correct permissions two queries are performed and the response is fused from that queries:
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 be nullignoreSearchExclude - 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 forCmsSearchException - if something goes wrongsearch(CmsObject, CmsSolrQuery, boolean)public CmsSolrResultList search(CmsObject cms, org.apache.solr.client.solrj.SolrQuery query) throws CmsSearchException
cms - the current CMS objectquery - the queryCmsSearchException - if something goes wrongsearch(CmsObject, String)public CmsSolrResultList search(CmsObject cms, java.lang.String solrQuery) throws CmsSearchException
cms - the cms objectsolrQuery - the Solr queryCmsSearchException - if something goes wrongsearch(CmsObject, CmsSolrQuery, boolean)public void select(javax.servlet.ServletResponse response, CmsObject cms, CmsSolrQuery query, boolean ignoreMaxRows) throws java.lang.Exception
NOTE: Currently not available for HTTP server.
response - the servlet responsecms - the CMS object to use for searchquery - the Solr queryignoreMaxRows - if to return unlimited resultsjava.lang.Exception - if there is no embedded serverpublic void setName(java.lang.String name) throws CmsIllegalArgumentException
setName in interface I_CmsSearchIndexsetName in class A_CmsSearchIndexname - the logical key/name of this search indexCmsIllegalArgumentException - if the given name is null, empty or already taken by another search indexI_CmsSearchIndex.setName(java.lang.String)public void setPostProcessor(I_CmsSolrPostSearchProcessor postProcessor)
postProcessor - the search post processor to setpublic void setSolrServer(org.apache.solr.client.solrj.SolrClient client)
client - the server to setpublic void spellCheck(javax.servlet.ServletResponse res, CmsObject cms, CmsSolrQuery q) throws CmsSearchException
res - the servlet responsecms - the CMS objectq - the queryCmsSearchException - if something goes wrongprotected java.lang.String createIndexBackup()
CmsSearchIndexcreateIndexBackup in class CmsSearchIndexnull in case no backup was createdCmsSearchIndex.createIndexBackup()protected boolean hasPermissions(CmsObject cms, CmsSolrDocument doc, CmsResourceFilter filter)
cms - the contextdoc - the solr document (from the search result)filter - the resource filter to use for checking permissionstrue iff the resource mirrored by the search result can be read by the current user.protected void indexSearcherClose()
CmsSearchIndexindexSearcherClose in class CmsSearchIndexCmsSearchIndex.indexSearcherClose()protected void indexSearcherOpen(java.lang.String path)
CmsSearchIndexIn 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.
indexSearcherOpen in class CmsSearchIndexpath - the path to the index directoryCmsSearchIndex.indexSearcherOpen(java.lang.String)protected void indexSearcherUpdate()
CmsSearchIndexindexSearcherUpdate in class CmsSearchIndexCmsSearchIndex.indexSearcherUpdate()protected boolean isIndexing(CmsResource res)
isIndexing in class A_CmsSearchIndexres - the resource candidatetrue if the given resource should be indexed or false if not