Class CmsSearchIndex
- java.lang.Object
-
- org.opencms.search.A_CmsSearchIndex
-
- org.opencms.search.CmsSearchIndex
-
- All Implemented Interfaces:
java.io.Serializable
,I_CmsConfigurationParameterHandler
,I_CmsSearchIndex
- Direct Known Subclasses:
CmsSolrIndex
public class CmsSearchIndex extends A_CmsSearchIndex
Abstract search index implementation.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
A_PARAM_PREFIX
A constant for the full qualified name of the CmsSearchIndex class.static java.lang.String
BACKUP_REINDEXING
Constant for additional parameter to enable optimized full index regeneration (default: false).static java.lang.String[]
DATES
Look table to quickly zero-pad days / months in date Strings.static java.lang.String[]
DOC_META_FIELDS
Constant for a field list that contains the "meta" field as well as the "content" field.static java.lang.String
EXCERPT
Constant for additional parameter to enable excerpt creation (default: true).static java.lang.String
EXTRACT_CONTENT
Constant for additional parameter for index content extraction.static java.lang.String
IGNORE_EXPIRATION
Constant for additional parameter to enable/disable language detection (default: false).static java.lang.String
LANGUAGEDETECTION
Constant for additional parameter to enable/disable language detection (default: false).static java.lang.String
LUCENE_AUTO_COMMIT
Constant for additional parameter for the Lucene index setting.static java.lang.String
LUCENE_RAM_BUFFER_SIZE_MB
Constant for additional parameter for the Lucene index setting.static java.lang.String
MAX_HITS
Constant for additional parameter for controlling how many hits are loaded at maximum (default: 1000).static int
MAX_HITS_DEFAULT
Indicates how many hits are loaded at maximum by default.static int
MAX_YEAR_RANGE
Constant for years max range span in document search.static java.lang.String
PERMISSIONS
Constant for additional parameter to enable permission checks (default: true).static java.lang.String
PRIORITY
Constant for additional parameter to set the thread priority during search.static java.lang.String
TIME_RANGE
Constant for additional parameter to enable time range checks (default: true).protected static org.apache.lucene.index.StoredFieldVisitor
VISITOR
A stored field visitor, that does not return the large fields: "content" and "contentblob".-
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
Constructors Constructor Description CmsSearchIndex()
Default constructor only intended to be used by the XML configuration.CmsSearchIndex(java.lang.String name)
Creates a new CmsSearchIndex with the given name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addConfigurationParameter(java.lang.String key, java.lang.String value)
Adds a parameter.protected org.apache.lucene.search.BooleanQuery.Builder
appendCategoryFilter(CmsObject cms, org.apache.lucene.search.BooleanQuery.Builder filter, java.util.List<java.lang.String> categories)
Appends the a category filter to the given filter clause that matches all given categories.protected org.apache.lucene.search.BooleanQuery.Builder
appendDateCreatedFilter(org.apache.lucene.search.BooleanQuery.Builder filter, long startTime, long endTime)
Appends a date of creation filter to the given filter clause that matches the given time range.protected org.apache.lucene.search.BooleanQuery.Builder
appendDateLastModifiedFilter(org.apache.lucene.search.BooleanQuery.Builder filter, long startTime, long endTime)
Appends a date of last modification filter to the given filter clause that matches the given time range.protected org.apache.lucene.search.BooleanQuery.Builder
appendPathFilter(CmsObject cms, org.apache.lucene.search.BooleanQuery.Builder filter, java.util.List<java.lang.String> roots)
Appends the a VFS path filter to the given filter clause that matches all given root paths.protected org.apache.lucene.search.BooleanQuery.Builder
appendResourceTypeFilter(CmsObject cms, org.apache.lucene.search.BooleanQuery.Builder filter, java.util.List<java.lang.String> resourceTypes)
Appends the a resource type filter to the given filter clause that matches all given resource types.protected org.apache.lucene.search.Query
createDateRangeFilter(java.lang.String fieldName, long startTime, long endTime)
Creates an optimized date range filter for the date of last modification or creation.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.protected I_CmsIndexWriter
createIndexWriter(boolean create, I_CmsReport report)
Creates a new index writer.protected void
extendPathFilter(java.util.List<org.apache.lucene.index.Term> terms, java.lang.String searchRoot)
Extends the given path query with another term for the given search root element.protected java.lang.String
generateIndexDirectory()
Generates the directory on the RFS for this index.org.apache.lucene.analysis.Analyzer
getAnalyzer()
Returns the Lucene analyzer used for this index.CmsParameterConfiguration
getConfiguration()
Returns the empty configuration.I_CmsExtractionResult
getContentIfUnchanged(CmsResource resource)
We always assume we have no unchanged copy of the content, since it depends on the concrete index.static java.util.List<java.lang.String>
getDateRangeSpan(long startDate, long endDate)
Generates a list of date terms for the optimized date range search with "daily" granularity level.I_CmsSearchDocument
getDocument(int docId)
Returns a document by document ID.org.apache.lucene.document.Document
getDocument(java.lang.String rootPath)
Deprecated.UsegetDocument(String, String)
instead and provideCmsSearchField.FIELD_PATH
as field to search inI_CmsSearchDocument
getDocument(java.lang.String field, java.lang.String term)
Returns the first document where the given term matches the selected index field.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.java.lang.String
getLocaleString()
Returns the language locale of the index as a String.int
getMaxHits()
Indicates the number of how many hits are loaded at maximum.protected org.apache.lucene.search.Query
getMultiTermQueryFilter(java.lang.String field, java.lang.String terms)
Returns a cached Lucene term query filter for the given field and terms.protected org.apache.lucene.search.Query
getMultiTermQueryFilter(java.lang.String field, java.lang.String termsStr, java.util.List<java.lang.String> termsList)
Returns a cached Lucene term query filter for the given field and terms.protected org.apache.lucene.search.Query
getMultiTermQueryFilter(java.lang.String field, java.util.List<java.lang.String> terms)
Returns a cached Lucene term query filter for the given field and terms.java.lang.String
getPath()
Returns the path where this index stores it's data in the "real" file system.int
getPriority()
Returns the Thread priority for this search index.protected CmsResource
getResource(CmsObject cms, I_CmsSearchDocument doc)
Checks if the OpenCms resource referenced by the result document can be read by the user of the given OpenCms context.protected CmsResource
getResource(CmsObject cms, I_CmsSearchDocument doc, CmsResourceFilter filter)
Checks if the OpenCms resource referenced by the result document can be read by the user of the given OpenCms context.org.apache.lucene.search.IndexSearcher
getSearcher()
Returns the Lucene index searcher used for this search index.protected org.apache.lucene.search.Query
getTermQueryFilter(java.lang.String field, java.lang.String term)
Returns a cached Lucene term query filter for the given field and term.protected boolean
hasReadPermission(CmsObject cms, I_CmsSearchDocument doc)
Checks if the OpenCms resource referenced by the result document can be read be the user of the given OpenCms context.protected void
indexSearcherClose()
Closes the index searcher for this index.protected void
indexSearcherClose(org.apache.lucene.search.IndexSearcher searcher)
Closes the given Lucene index searcher.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.boolean
isBackupReindexing()
Returnstrue
if backup re-indexing is done by this index.boolean
isCheckingPermissions()
Returnstrue
if permissions are checked for search results by this index.boolean
isCheckingTimeRange()
Returnstrue
if the document time range is checked with a granularity level of seconds for search results by this index.boolean
isCheckPermissions()
Returns the checkPermissions.boolean
isCreatingExcerpt()
Returnstrue
if an excerpt is generated by this index.boolean
isIgnoreExpiration()
Returns the ignoreExpiration.boolean
isInitialized()
Returns a flag, indicating if the search index is successfully initialized.protected boolean
isInTimeRange(org.apache.lucene.document.Document doc, CmsSearchParameters params)
Checks if the document is in the time range specified in the search parameters.boolean
isRequireViewPermission()
Returnstrue
if a resource requires read permission to be included in the result list.protected boolean
isSortScoring(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Sort sort)
Checks if the score for the results must be calculated based on the provided sort option.protected boolean
needsPermissionCheck(I_CmsSearchDocument doc)
Checks if the OpenCms resource referenced by the result document needs to be checked.void
onIndexChanged(boolean force)
Method called by the search manager if the index has changed.protected void
removeIndexBackup(java.lang.String path)
Removes the given backup folder of this index.CmsSearchResultList
search(CmsObject cms, CmsSearchParameters params)
Performs a search on the index within the given fields.void
setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
Sets the Lucene analyzer used for this index.void
setCheckPermissions(boolean checkPermissions)
Sets the checkPermissions.void
setIgnoreExpiration(boolean ignoreExpiration)
Sets the ignoreExpiration.void
setMaxHits(int maxHits)
Sets the number of how many hits are loaded at maximum.void
setRequireViewPermission(boolean requireViewPermission)
Controls if a resource requires view permission to be displayed in the result list.void
shutDown()
Shuts down the search index.java.lang.String
toString()
Returns the name (
) of this search index.A_CmsSearchIndex.getName()
-
Methods inherited from class org.opencms.search.A_CmsSearchIndex
addSourceName, checkConfiguration, equals, excludeFromIndex, 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, setName, setPath, setProject, setRebuildMode
-
-
-
-
Field Detail
-
A_PARAM_PREFIX
public static final java.lang.String A_PARAM_PREFIX
A constant for the full qualified name of the CmsSearchIndex class.- See Also:
- Constant Field Values
-
BACKUP_REINDEXING
public static final java.lang.String BACKUP_REINDEXING
Constant for additional parameter to enable optimized full index regeneration (default: false).- See Also:
- Constant Field Values
-
DATES
public static final java.lang.String[] DATES
Look table to quickly zero-pad days / months in date Strings.
-
DOC_META_FIELDS
public static final java.lang.String[] DOC_META_FIELDS
Constant for a field list that contains the "meta" field as well as the "content" field.
-
EXCERPT
public static final java.lang.String EXCERPT
Constant for additional parameter to enable excerpt creation (default: true).- See Also:
- Constant Field Values
-
EXTRACT_CONTENT
public static final java.lang.String EXTRACT_CONTENT
Constant for additional parameter for index content extraction.- See Also:
- Constant Field Values
-
IGNORE_EXPIRATION
public static final java.lang.String IGNORE_EXPIRATION
Constant for additional parameter to enable/disable language detection (default: false).- See Also:
- Constant Field Values
-
LANGUAGEDETECTION
public static final java.lang.String LANGUAGEDETECTION
Constant for additional parameter to enable/disable language detection (default: false).- See Also:
- Constant Field Values
-
LUCENE_AUTO_COMMIT
public static final java.lang.String LUCENE_AUTO_COMMIT
Constant for additional parameter for the Lucene index setting.- See Also:
- Constant Field Values
-
LUCENE_RAM_BUFFER_SIZE_MB
public static final java.lang.String LUCENE_RAM_BUFFER_SIZE_MB
Constant for additional parameter for the Lucene index setting.- See Also:
- Constant Field Values
-
MAX_HITS
public static final java.lang.String MAX_HITS
Constant for additional parameter for controlling how many hits are loaded at maximum (default: 1000).- See Also:
- Constant Field Values
-
MAX_HITS_DEFAULT
public static final int MAX_HITS_DEFAULT
Indicates how many hits are loaded at maximum by default.- See Also:
- Constant Field Values
-
MAX_YEAR_RANGE
public static final int MAX_YEAR_RANGE
Constant for years max range span in document search.- See Also:
- Constant Field Values
-
PERMISSIONS
public static final java.lang.String PERMISSIONS
Constant for additional parameter to enable permission checks (default: true).- See Also:
- Constant Field Values
-
PRIORITY
public static final java.lang.String PRIORITY
Constant for additional parameter to set the thread priority during search.- See Also:
- Constant Field Values
-
TIME_RANGE
public static final java.lang.String TIME_RANGE
Constant for additional parameter to enable time range checks (default: true).- See Also:
- Constant Field Values
-
VISITOR
protected static final org.apache.lucene.index.StoredFieldVisitor VISITOR
A stored field visitor, that does not return the large fields: "content" and "contentblob".
-
-
Constructor Detail
-
CmsSearchIndex
public CmsSearchIndex()
Default constructor only intended to be used by the XML configuration.It is recommended to use the constructor
as it enforces the mandatory name argument.CmsSearchIndex(String)
-
CmsSearchIndex
public CmsSearchIndex(java.lang.String name) throws CmsIllegalArgumentException
Creates a new CmsSearchIndex with the given name.- Parameters:
name
- the system-wide unique name for the search index- Throws:
CmsIllegalArgumentException
- if the given name is null, empty or already taken by another search index
-
-
Method Detail
-
getDateRangeSpan
public static java.util.List<java.lang.String> getDateRangeSpan(long startDate, long endDate)
Generates a list of date terms for the optimized date range search with "daily" granularity level.How this works:
- For each document, terms are added for the year, the month and the day the document was modified or created) in. So for example if a document is modified at February 02, 2009, then the following terms are stored for this document: "20090202", "200902" and "2009".
- In case a date range search is done, then all possible matches for the provided rage are created as search terms and matched with the document terms.
- Consider the following use case: You want to find out if a resource has been changed in the time between November 29, 2007 and March 01, 2009. One term to match is simply "2008" because if a document was modified in 2008, then it is clearly in the date range. Other terms are "200712", "200901" and "200902", because all documents modified in these months are also a certain matches. Finally we need to add terms for "20071129", "20071130" and "20090301" to match the days in the starting and final month.
- Parameters:
startDate
- start date of the range to search inendDate
- end date of the range to search in- Returns:
- a list of date terms for the optimized date range search
-
addConfigurationParameter
public void addConfigurationParameter(java.lang.String key, java.lang.String value)
Adds a parameter.- Specified by:
addConfigurationParameter
in interfaceI_CmsConfigurationParameterHandler
- Overrides:
addConfigurationParameter
in classA_CmsSearchIndex
- Parameters:
key
- the key/name of the parametervalue
- the value of the parameter- See Also:
I_CmsConfigurationParameterHandler.addConfigurationParameter(java.lang.String, java.lang.String)
-
createEmptyDocument
public I_CmsSearchDocument createEmptyDocument(CmsResource resource)
Creates an empty document that can be used by this search field configuration.- Parameters:
resource
- the resource to create the document for- Returns:
- a new and empty document
-
getAnalyzer
public org.apache.lucene.analysis.Analyzer getAnalyzer()
Returns the Lucene analyzer used for this index.- Returns:
- the Lucene analyzer used for this index
-
getConfiguration
public CmsParameterConfiguration 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 classA_CmsSearchIndex
- Returns:
- the parameters of this configurable class instance,
or
null
if the class does not need any parameters - See Also:
I_CmsConfigurationParameterHandler.getConfiguration()
-
getContentIfUnchanged
public I_CmsExtractionResult getContentIfUnchanged(CmsResource resource)
Description copied from class:A_CmsSearchIndex
We always assume we have no unchanged copy of the content, since it depends on the concrete index. Override the method to enhance indexing performance if you know where to grap the content from your index. See the implementationgetContentIfUnchanged(CmsResource)
for an example.- Specified by:
getContentIfUnchanged
in interfaceI_CmsSearchIndex
- Overrides:
getContentIfUnchanged
in classA_CmsSearchIndex
- Parameters:
resource
- the resource the content should be provided for.- Returns:
- the up-to-date extraction result as gained from the index - if possible, or
null
, if no up-to-date extraction result can be obtained from the index. - See Also:
I_CmsSearchIndex.getContentIfUnchanged(org.opencms.file.CmsResource)
-
getDocument
public I_CmsSearchDocument getDocument(int docId)
Returns a document by document ID.- Parameters:
docId
- the id to get the document for- Returns:
- the CMS specific document
-
getDocument
@Deprecated public org.apache.lucene.document.Document getDocument(java.lang.String rootPath)
Deprecated.UsegetDocument(String, String)
instead and provideCmsSearchField.FIELD_PATH
as field to search inReturns the Lucene document with the given root path from the index.- Parameters:
rootPath
- the root path of the document to get- Returns:
- the Lucene document with the given root path from the index
-
getDocument
public I_CmsSearchDocument getDocument(java.lang.String field, java.lang.String term)
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.
- Parameters:
field
- the field to search interm
- the term to search for- Returns:
- the first document where the given term matches the selected index field
-
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.- Specified by:
getLocaleForResource
in interfaceI_CmsSearchIndex
- Overrides:
getLocaleForResource
in classA_CmsSearchIndex
- 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
-
getLocaleString
public java.lang.String getLocaleString()
Returns the language locale of the index as a String.- Returns:
- the language locale of the index as a String
- See Also:
A_CmsSearchIndex.getLocale()
-
getMaxHits
public int getMaxHits()
Indicates the number of how many hits are loaded at maximum.The number of maximum documents to load from the index must be specified. The default of this setting is
MAX_HITS_DEFAULT
(5000). This means that at maximum 5000 results are returned from the index. Please note that this number may be reduced further because of OpenCms read permissions or per-user file visibility settings not controlled in the index.- Returns:
- the number of how many hits are loaded at maximum
- Since:
- 7.5.1
-
getPath
public java.lang.String getPath()
Returns the path where this index stores it's data in the "real" file system.- Specified by:
getPath
in interfaceI_CmsSearchIndex
- Overrides:
getPath
in classA_CmsSearchIndex
- Returns:
- the path where this index stores it's data in the "real" file system
- See Also:
I_CmsSearchIndex.getPath()
-
getPriority
public int getPriority()
Returns the Thread priority for this search index.- Returns:
- the Thread priority for this search index
-
getSearcher
public org.apache.lucene.search.IndexSearcher getSearcher()
Returns the Lucene index searcher used for this search index.- Returns:
- the Lucene index searcher used for this search index
-
initialize
public void initialize() throws CmsSearchException
Description copied from class:A_CmsSearchIndex
Initializes the search index.- Specified by:
initialize
in interfaceI_CmsSearchIndex
- Overrides:
initialize
in classA_CmsSearchIndex
- Throws:
CmsSearchException
- if the index source association failed or a configuration error occurred- See Also:
A_CmsSearchIndex.initialize()
-
isBackupReindexing
public boolean isBackupReindexing()
Returnstrue
if backup re-indexing is done by this index.This is an optimization method by which the old extracted content is reused in order to save performance when re-indexing.
- Returns:
true
if backup re-indexing is done by this index- Since:
- 7.5.1
-
isCheckingPermissions
public boolean isCheckingPermissions()
Returnstrue
if permissions are checked for search results by this index.If permission checks are not required, they can be turned off in the index search configuration parameters in
opencms-search.xml
. Not checking permissions will improve performance.This is can be of use in scenarios when you know that all search results are always readable, which is usually true for public websites that do not have personalized accounts.
Please note that even if a result is returned where the current user has no read permissions, the user can not actually access this document. It will only appear in the search result list, but if the user clicks the link to open the document he will get an error.
- Returns:
true
if permissions are checked for search results by this index
-
isCheckingTimeRange
public boolean isCheckingTimeRange()
Returnstrue
if the document time range is checked with a granularity level of seconds for search results by this index.Since OpenCms 8.0, time range checks are always done if
CmsSearchParameters.setMinDateLastModified(long)
or any of the corresponding methods are used. This is done very efficiently using optimized Lucene filers. However, the granularity of these checks are done only on a daily basis, which means that you can only find "changes made yesterday" but not "changes made last hour". For normal limitation of search results, a daily granularity should be enough.If time range checks with a granularity level of seconds are required, they can be turned on in the index search configuration parameters in
opencms-search.xml
. Not checking the time range with a granularity level of seconds will improve performance.By default the granularity level of seconds is turned off since OpenCms 8.0
- Returns:
true
if the document time range is checked with a granularity level of seconds for search results by this index
-
isCheckPermissions
public boolean isCheckPermissions()
Returns the checkPermissions.- Returns:
- the checkPermissions
-
isCreatingExcerpt
public boolean isCreatingExcerpt()
Returnstrue
if an excerpt is generated by this index.If no except is required, generation can be turned off in the index search configuration parameters in
opencms-search.xml
. Not generating an excerpt will improve performance.- Returns:
true
if an excerpt is generated by this index
-
isIgnoreExpiration
public boolean isIgnoreExpiration()
Returns the ignoreExpiration.- Returns:
- the ignoreExpiration
-
isInitialized
public boolean isInitialized()
Description copied from interface:I_CmsSearchIndex
Returns a flag, indicating if the search index is successfully initialized.- Specified by:
isInitialized
in interfaceI_CmsSearchIndex
- Overrides:
isInitialized
in classA_CmsSearchIndex
- Returns:
- a flag, indicating if the search index is successfully initialized.
- See Also:
A_CmsSearchIndex.isInitialized()
-
isRequireViewPermission
public boolean isRequireViewPermission()
Returnstrue
if a resource requires read permission to be included in the result list.- Returns:
true
if a resource requires read permission to be included in the result list
-
onIndexChanged
public void onIndexChanged(boolean force)
Description copied from interface:I_CmsSearchIndex
Method called by the search manager if the index has changed. Typically the index searcher is reset when the method is called.- Specified by:
onIndexChanged
in interfaceI_CmsSearchIndex
- Overrides:
onIndexChanged
in classA_CmsSearchIndex
- Parameters:
force
- iffalse
the index might decide itself it it has to act on the change, iftrue
it should act, even if itself cannot detect an index change.- See Also:
A_CmsSearchIndex.onIndexChanged(boolean)
-
search
public CmsSearchResultList search(CmsObject cms, CmsSearchParameters params) throws CmsSearchException
Performs a search on the index within the given fields.The result is returned as List with entries of type I_CmsSearchResult.
- 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
- Throws:
CmsSearchException
- if something goes wrong
-
setAnalyzer
public void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
Sets the Lucene analyzer used for this index.- Parameters:
analyzer
- the Lucene analyzer to set
-
setCheckPermissions
public void setCheckPermissions(boolean checkPermissions)
Sets the checkPermissions.- Parameters:
checkPermissions
- the checkPermissions to set
-
setIgnoreExpiration
public void setIgnoreExpiration(boolean ignoreExpiration)
Sets the ignoreExpiration.- Parameters:
ignoreExpiration
- the ignoreExpiration to set
-
setMaxHits
public void setMaxHits(int maxHits)
Sets the number of how many hits are loaded at maximum.This must be set at least to 50, or this setting is ignored.
- Parameters:
maxHits
- the number of how many hits are loaded at maximum to set- Since:
- 7.5.1
- See Also:
getMaxHits()
-
setRequireViewPermission
public void setRequireViewPermission(boolean requireViewPermission)
Controls if a resource requires view permission to be displayed in the result list.By default this is
false
.- Parameters:
requireViewPermission
- controls if a resource requires view permission to be displayed in the result list
-
shutDown
public void shutDown()
Shuts down the search index.This will close the local Lucene index searcher instance.
- Specified by:
shutDown
in interfaceI_CmsSearchIndex
- Overrides:
shutDown
in classA_CmsSearchIndex
- See Also:
I_CmsSearchIndex.shutDown()
-
toString
public java.lang.String toString()
Returns the name (
) of this search index.A_CmsSearchIndex.getName()
- Overrides:
toString
in classjava.lang.Object
- Returns:
- the name (
) of this search indexA_CmsSearchIndex.getName()
- See Also:
Object.toString()
-
appendCategoryFilter
protected org.apache.lucene.search.BooleanQuery.Builder appendCategoryFilter(CmsObject cms, org.apache.lucene.search.BooleanQuery.Builder filter, java.util.List<java.lang.String> categories)
Appends the a category filter to the given filter clause that matches all given categories.In case the provided List is null or empty, the original filter is left unchanged.
The original filter parameter is extended and also provided as return value.
- Parameters:
cms
- the current OpenCms search contextfilter
- the filter to extendcategories
- the categories that will compose the filter- Returns:
- the extended filter clause
-
appendDateCreatedFilter
protected org.apache.lucene.search.BooleanQuery.Builder appendDateCreatedFilter(org.apache.lucene.search.BooleanQuery.Builder filter, long startTime, long endTime)
Appends a date of creation filter to the given filter clause that matches the given time range.If the start time is equal to
Long.MIN_VALUE
and the end time is equal toLong.MAX_VALUE
than the original filter is left unchanged.The original filter parameter is extended and also provided as return value.
- Parameters:
filter
- the filter to extendstartTime
- start time of the range to search inendTime
- end time of the range to search in- Returns:
- the extended filter clause
-
appendDateLastModifiedFilter
protected org.apache.lucene.search.BooleanQuery.Builder appendDateLastModifiedFilter(org.apache.lucene.search.BooleanQuery.Builder filter, long startTime, long endTime)
Appends a date of last modification filter to the given filter clause that matches the given time range.If the start time is equal to
Long.MIN_VALUE
and the end time is equal toLong.MAX_VALUE
than the original filter is left unchanged.The original filter parameter is extended and also provided as return value.
- Parameters:
filter
- the filter to extendstartTime
- start time of the range to search inendTime
- end time of the range to search in- Returns:
- the extended filter clause
-
appendPathFilter
protected org.apache.lucene.search.BooleanQuery.Builder appendPathFilter(CmsObject cms, org.apache.lucene.search.BooleanQuery.Builder filter, java.util.List<java.lang.String> roots)
Appends the a VFS path filter to the given filter clause that matches all given root paths.In case the provided List is null or empty, the current request context site root is appended.
The original filter parameter is extended and also provided as return value.
- Parameters:
cms
- the current OpenCms search contextfilter
- the filter to extendroots
- the VFS root paths that will compose the filter- Returns:
- the extended filter clause
-
appendResourceTypeFilter
protected org.apache.lucene.search.BooleanQuery.Builder appendResourceTypeFilter(CmsObject cms, org.apache.lucene.search.BooleanQuery.Builder filter, java.util.List<java.lang.String> resourceTypes)
Appends the a resource type filter to the given filter clause that matches all given resource types.In case the provided List is null or empty, the original filter is left unchanged.
The original filter parameter is extended and also provided as return value.
- Parameters:
cms
- the current OpenCms search contextfilter
- the filter to extendresourceTypes
- the resource types that will compose the filter- Returns:
- the extended filter clause
-
createDateRangeFilter
protected org.apache.lucene.search.Query createDateRangeFilter(java.lang.String fieldName, long startTime, long endTime)
Creates an optimized date range filter for the date of last modification or creation.If the start date is equal to
Long.MIN_VALUE
and the end date is equal toLong.MAX_VALUE
thannull
is returned.- Parameters:
fieldName
- the name of the field to searchstartTime
- start time of the range to search inendTime
- end time of the range to search in- Returns:
- an optimized date range filter for the date of last modification or creation
-
createIndexBackup
protected java.lang.String createIndexBackup()
Creates a backup of this index for optimized re-indexing of the whole content.- Returns:
- the path to the backup folder, or
null
in case no backup was created
-
createIndexWriter
protected I_CmsIndexWriter createIndexWriter(boolean create, I_CmsReport report) throws CmsIndexException
Creates a new index writer.- Specified by:
createIndexWriter
in classA_CmsSearchIndex
- Parameters:
create
- iftrue
a whole new index is created, iffalse
an existing index is updatedreport
- the report- Returns:
- the created new index writer
- Throws:
CmsIndexException
- in case the writer could not be created- See Also:
A_CmsSearchIndex.getIndexWriter(I_CmsReport, boolean)
-
extendPathFilter
protected void extendPathFilter(java.util.List<org.apache.lucene.index.Term> terms, java.lang.String searchRoot)
Extends the given path query with another term for the given search root element.- Parameters:
terms
- the path filter to extendsearchRoot
- the search root to add to the path query
-
generateIndexDirectory
protected java.lang.String generateIndexDirectory()
Generates the directory on the RFS for this index.- Returns:
- the directory on the RFS for this index
-
getMultiTermQueryFilter
protected org.apache.lucene.search.Query getMultiTermQueryFilter(java.lang.String field, java.util.List<java.lang.String> terms)
Returns a cached Lucene term query filter for the given field and terms.- Parameters:
field
- the field to useterms
- the term to use- Returns:
- a cached Lucene term query filter for the given field and terms
-
getMultiTermQueryFilter
protected org.apache.lucene.search.Query getMultiTermQueryFilter(java.lang.String field, java.lang.String terms)
Returns a cached Lucene term query filter for the given field and terms.- Parameters:
field
- the field to useterms
- the term to use- Returns:
- a cached Lucene term query filter for the given field and terms
-
getMultiTermQueryFilter
protected org.apache.lucene.search.Query getMultiTermQueryFilter(java.lang.String field, java.lang.String termsStr, java.util.List<java.lang.String> termsList)
Returns a cached Lucene term query filter for the given field and terms.- Parameters:
field
- the field to usetermsStr
- the terms to use as a String separated by a space ' ' chartermsList
- the list of terms to use- Returns:
- a cached Lucene term query filter for the given field and terms
-
getResource
protected CmsResource getResource(CmsObject cms, I_CmsSearchDocument doc)
Checks if the OpenCms resource referenced by the result document can be read by the user of the given OpenCms context. Returns the referencedCmsResource
ornull
if the user is not permitted to read the resource.- Parameters:
cms
- the OpenCms user context to use for permission testingdoc
- the search result document to check- Returns:
- the referenced
CmsResource
ornull
if the user is not permitted
-
getResource
protected CmsResource getResource(CmsObject cms, I_CmsSearchDocument doc, CmsResourceFilter filter)
Checks if the OpenCms resource referenced by the result document can be read by the user of the given OpenCms context. Returns the referencedCmsResource
ornull
if the user is not permitted to read the resource.- Parameters:
cms
- the OpenCms user context to use for permission testingdoc
- the search result document to checkfilter
- the resource filter to apply- Returns:
- the referenced
CmsResource
ornull
if the user is not permitted
-
getTermQueryFilter
protected org.apache.lucene.search.Query getTermQueryFilter(java.lang.String field, java.lang.String term)
Returns a cached Lucene term query filter for the given field and term.- Parameters:
field
- the field to useterm
- the term to use- Returns:
- a cached Lucene term query filter for the given field and term
-
hasReadPermission
protected boolean hasReadPermission(CmsObject cms, I_CmsSearchDocument doc)
Checks if the OpenCms resource referenced by the result document can be read be the user of the given OpenCms context.- Parameters:
cms
- the OpenCms user context to use for permission testingdoc
- the search result document to check- Returns:
true
if the user has read permissions to the resource
-
indexSearcherClose
protected void indexSearcherClose()
Closes the index searcher for this index.- See Also:
indexSearcherOpen(String)
-
indexSearcherClose
protected void indexSearcherClose(org.apache.lucene.search.IndexSearcher searcher)
Closes the given Lucene index searcher.- Parameters:
searcher
- the searcher to close
-
indexSearcherOpen
protected void indexSearcherOpen(java.lang.String path)
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.
- Parameters:
path
- the path to the index directory
-
indexSearcherUpdate
protected void indexSearcherUpdate()
Reopens the index search reader for this index, required after the index has been changed.- See Also:
indexSearcherOpen(String)
-
isInTimeRange
protected boolean isInTimeRange(org.apache.lucene.document.Document doc, CmsSearchParameters params)
Checks if the document is in the time range specified in the search parameters.The creation date and/or the last modification date are checked.
- Parameters:
doc
- the document to check the dates against the given time rangeparams
- the search parameters where the time ranges are specified- Returns:
- true if document is in time range or not time range set otherwise false
-
isSortScoring
protected boolean isSortScoring(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Sort sort)
Checks if the score for the results must be calculated based on the provided sort option.Since Lucene 3 apparently the score is no longer calculated by default, but only if the searcher is explicitly told so. This methods checks if, based on the given sort, the score must be calculated.
- Parameters:
searcher
- the index searcher to preparesort
- the sort option to use- Returns:
- true if the sort option should be used
-
needsPermissionCheck
protected boolean needsPermissionCheck(I_CmsSearchDocument doc)
Checks if the OpenCms resource referenced by the result document needs to be checked.- Parameters:
doc
- the search result document to check- Returns:
true
if the document needs to be checkedfalse
otherwise
-
removeIndexBackup
protected void removeIndexBackup(java.lang.String path)
Removes the given backup folder of this index.- Parameters:
path
- the backup folder to remove
-
-