org.opencms.search.fields
Class CmsSearchFieldConfiguration

java.lang.Object
  extended by org.opencms.search.fields.CmsSearchFieldConfiguration
All Implemented Interfaces:
Comparable<CmsSearchFieldConfiguration>
Direct Known Subclasses:
CmsGallerySearchFieldConfiguration, CmsSearchFieldConfigurationOldCategories

public class CmsSearchFieldConfiguration
extends Object
implements Comparable<CmsSearchFieldConfiguration>

Describes a configuration of fields that are used in building a search index.

Since:
7.0.0

Field Summary
static CmsSearchFieldConfiguration DEFAULT_STANDARD
          The default for the standard search configuration.
static String SEARCH_PRIORITY_HIGH_VALUE
          Value for "high" search priority.
static String SEARCH_PRIORITY_LOW_VALUE
          Value for "low" search priority.
static String SEARCH_PRIORITY_MAX_VALUE
          Value for "maximum" search priority.
static String SEARCH_PRIORITY_NORMAL_VALUE
          Value for "normal" search priority.
static String STR_STANDARD
          The name for the standard field configuration.
static String STR_STANDARD_DESCRIPTION
          The description for the standard field configuration.
static String VFS_DOCUMENT_KEY_PREFIX
          The VFS prefix for document keys.
 
Constructor Summary
CmsSearchFieldConfiguration()
          Creates a new, empty field configuration.
 
Method Summary
 void addField(CmsSearchField field)
          Adds a field to this search field configuration.
protected  org.apache.lucene.document.Document appendCategories(org.apache.lucene.document.Document document, CmsObject cms, CmsResource resource, I_CmsExtractionResult extractionResult, List<CmsProperty> properties, List<CmsProperty> propertiesSearched)
          Extends the given document by resource category information.
protected  org.apache.lucene.document.Document appendContentBlob(org.apache.lucene.document.Document document, CmsObject cms, CmsResource resource, I_CmsExtractionResult extractionResult, List<CmsProperty> properties, List<CmsProperty> propertiesSearched)
          Extends the given document by a field that contains the extracted content blob.
protected  org.apache.lucene.document.Document appendDates(org.apache.lucene.document.Document document, CmsObject cms, CmsResource resource, I_CmsExtractionResult extractionResult, List<CmsProperty> properties, List<CmsProperty> propertiesSearched)
          Extends the given document by fields for date of creation, content and last modification.
protected  org.apache.lucene.document.Document appendFieldMapping(org.apache.lucene.document.Document document, CmsSearchField fieldConfig, CmsObject cms, CmsResource resource, I_CmsExtractionResult extractionResult, List<CmsProperty> properties, List<CmsProperty> propertiesSearched)
          Extends the given document by the mappings for the given field.
protected  org.apache.lucene.document.Document appendFieldMappings(org.apache.lucene.document.Document document, CmsObject cms, CmsResource resource, I_CmsExtractionResult extractionResult, List<CmsProperty> properties, List<CmsProperty> propertiesSearched)
          Extends the given document by the configured field mappings.
protected  org.apache.lucene.document.Document appendPath(org.apache.lucene.document.Document document, CmsObject cms, CmsResource resource, I_CmsExtractionResult extractionResult, List<CmsProperty> properties, List<CmsProperty> propertiesSearched)
          Extends the given document by fields for VFS path lookup.
protected  org.apache.lucene.document.Document appendType(org.apache.lucene.document.Document document, CmsObject cms, CmsResource resource, I_CmsExtractionResult extractionResult, List<CmsProperty> properties, List<CmsProperty> propertiesSearched)
          Extends the given document by a field that contains the resource type name.
 int compareTo(CmsSearchFieldConfiguration obj)
           
 org.apache.lucene.document.Document createDocument(CmsObject cms, CmsResource resource, CmsSearchIndex index, I_CmsExtractionResult content)
          Creates the Lucene Document with this field configuration for the provided VFS resource, search index and content.
 boolean equals(Object obj)
           
 org.apache.lucene.analysis.Analyzer getAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
          Returns an analyzer that wraps the given base analyzer with the analyzers of this individual field configuration.
protected  org.apache.lucene.analysis.Analyzer getAnalyzerForDefaultFields(org.apache.lucene.analysis.Analyzer analyzer)
          Returns an analyzer that wraps the given base analyzer with special analyzers required for the hard coded document fields.
static String getDateTerms(long date)
          Generate a list of date terms for the optimized date range search.
 String getDescription()
          Returns the description of this field configuration.
 List<String> getExcerptFieldNames()
          Returns a list of all field names (Strings) that are used in generating the search excerpt.
 CmsSearchField getField(String name)
          Returns the configured CmsSearchField instance with the given name.
 List<String> getFieldNames()
          Returns the list of configured field names (Strings).
 List<CmsSearchField> getFields()
          Returns the list of configured CmsSearchField instances.
 String getName()
          Returns the name of this field configuration.
static String getParentFolderTokens(String rootPath)
          Creates a space separated list of all parent folders of the given root path.
 int hashCode()
           
protected  org.apache.lucene.document.Document setBoost(org.apache.lucene.document.Document document, CmsObject cms, CmsResource resource, I_CmsExtractionResult extractionResult, List<CmsProperty> properties, List<CmsProperty> propertiesSearched)
          Extends the given document with a boost factor.
 void setDescription(String description)
          Sets the description of this field configuration.
 void setName(String name)
          Sets the name of this field configuration.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_STANDARD

public static final CmsSearchFieldConfiguration DEFAULT_STANDARD
The default for the standard search configuration.

This defines the default that is used in case no "standard" field configuration is defined in opencms-search.xml.


SEARCH_PRIORITY_HIGH_VALUE

public static final String SEARCH_PRIORITY_HIGH_VALUE
Value for "high" search priority.

See Also:
Constant Field Values

SEARCH_PRIORITY_LOW_VALUE

public static final String SEARCH_PRIORITY_LOW_VALUE
Value for "low" search priority.

See Also:
Constant Field Values

SEARCH_PRIORITY_MAX_VALUE

public static final String SEARCH_PRIORITY_MAX_VALUE
Value for "maximum" search priority.

See Also:
Constant Field Values

SEARCH_PRIORITY_NORMAL_VALUE

public static final String SEARCH_PRIORITY_NORMAL_VALUE
Value for "normal" search priority.

See Also:
Constant Field Values

STR_STANDARD

public static final String STR_STANDARD
The name for the standard field configuration.

See Also:
Constant Field Values

STR_STANDARD_DESCRIPTION

public static final String STR_STANDARD_DESCRIPTION
The description for the standard field configuration.

See Also:
Constant Field Values

VFS_DOCUMENT_KEY_PREFIX

public static final String VFS_DOCUMENT_KEY_PREFIX
The VFS prefix for document keys.

See Also:
Constant Field Values
Constructor Detail

CmsSearchFieldConfiguration

public CmsSearchFieldConfiguration()
Creates a new, empty field configuration.

Method Detail

getDateTerms

public static String getDateTerms(long date)
Generate a list of date terms for the optimized date range search.

Parameters:
date - the date for get the date terms for
Returns:
a list of date terms for the optimized date range search
See Also:
CmsSearchIndex.getDateRangeSpan(long, long)

getParentFolderTokens

public static String getParentFolderTokens(String rootPath)
Creates a space separated list of all parent folders of the given root path.

Parameters:
rootPath - the root path to get the parent folder list for
Returns:
a space separated list of all parent folders of the given root path

addField

public void addField(CmsSearchField field)
Adds a field to this search field configuration.

Parameters:
field - the field to add

compareTo

public int compareTo(CmsSearchFieldConfiguration obj)
Specified by:
compareTo in interface Comparable<CmsSearchFieldConfiguration>
See Also:
Comparable.compareTo(java.lang.Object)

createDocument

public org.apache.lucene.document.Document createDocument(CmsObject cms,
                                                          CmsResource resource,
                                                          CmsSearchIndex index,
                                                          I_CmsExtractionResult content)
                                                   throws CmsException
Creates the Lucene Document with this field configuration for the provided VFS resource, search index and content.

This triggers the indexing process for the given VFS resource according to the configuration of the provided index.

The provided index resource contains the basic contents to index. The provided search index contains the configuration what to index, such as the locale and possible special field mappings.

Parameters:
cms - the OpenCms user context used to access the OpenCms VFS
resource - the resource to create the Lucene document from
index - the search index to create the Document for
content - the plain text content extracted from the document
Returns:
the Lucene Document for the given VFS resource and the given search index
Throws:
CmsException - if something goes wrong

equals

public boolean equals(Object obj)
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

getAnalyzer

public org.apache.lucene.analysis.Analyzer getAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
Returns an analyzer that wraps the given base analyzer with the analyzers of this individual field configuration.

Parameters:
analyzer - the base analyzer to wrap
Returns:
an analyzer that wraps the given base analyzer with the analyzers of this individual field configuration

getDescription

public String getDescription()
Returns the description of this field configuration.

Returns:
the description of this field configuration

getExcerptFieldNames

public List<String> getExcerptFieldNames()
Returns a list of all field names (Strings) that are used in generating the search excerpt.

Returns:
a list of all field names (Strings) that are used in generating the search excerpt

getField

public CmsSearchField getField(String name)
Returns the configured CmsSearchField instance with the given name.

Parameters:
name - the search field name to look up
Returns:
the configured CmsSearchField instance with the given name

getFieldNames

public List<String> getFieldNames()
Returns the list of configured field names (Strings).

Returns:
the list of configured field names (Strings)

getFields

public List<CmsSearchField> getFields()
Returns the list of configured CmsSearchField instances.

Returns:
the list of configured CmsSearchField instances

getName

public String getName()
Returns the name of this field configuration.

Returns:
the name of this field configuration

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

setDescription

public void setDescription(String description)
Sets the description of this field configuration.

Parameters:
description - the description to set

setName

public void setName(String name)
Sets the name of this field configuration.

Parameters:
name - the name to set

appendCategories

protected org.apache.lucene.document.Document appendCategories(org.apache.lucene.document.Document document,
                                                               CmsObject cms,
                                                               CmsResource resource,
                                                               I_CmsExtractionResult extractionResult,
                                                               List<CmsProperty> properties,
                                                               List<CmsProperty> propertiesSearched)
                                                        throws CmsException
Extends the given document by resource category information.

Parameters:
document - the document to extend
cms - the OpenCms context used for building the search index
resource - the resource that is indexed
extractionResult - the plain text extraction result from the resource
properties - the list of all properties directly attached to the resource (not searched)
propertiesSearched - the list of all searched properties of the resource
Returns:
the document extended by resource category information
Throws:
CmsException - in case of an error accessing the resource categories

appendContentBlob

protected org.apache.lucene.document.Document appendContentBlob(org.apache.lucene.document.Document document,
                                                                CmsObject cms,
                                                                CmsResource resource,
                                                                I_CmsExtractionResult extractionResult,
                                                                List<CmsProperty> properties,
                                                                List<CmsProperty> propertiesSearched)
Extends the given document by a field that contains the extracted content blob.

Parameters:
document - the document to extend
cms - the OpenCms context used for building the search index
resource - the resource that is indexed
extractionResult - the plain text extraction result from the resource
properties - the list of all properties directly attached to the resource (not searched)
propertiesSearched - the list of all searched properties of the resource
Returns:
the document extended by a field that contains the extracted content blob

appendDates

protected org.apache.lucene.document.Document appendDates(org.apache.lucene.document.Document document,
                                                          CmsObject cms,
                                                          CmsResource resource,
                                                          I_CmsExtractionResult extractionResult,
                                                          List<CmsProperty> properties,
                                                          List<CmsProperty> propertiesSearched)
Extends the given document by fields for date of creation, content and last modification.

Parameters:
document - the document to extend
cms - the OpenCms context used for building the search index
resource - the resource that is indexed
extractionResult - the plain text extraction result from the resource
properties - the list of all properties directly attached to the resource (not searched)
propertiesSearched - the list of all searched properties of the resource
Returns:
the document extended by fields for date of creation, content and last modification

appendFieldMapping

protected org.apache.lucene.document.Document appendFieldMapping(org.apache.lucene.document.Document document,
                                                                 CmsSearchField fieldConfig,
                                                                 CmsObject cms,
                                                                 CmsResource resource,
                                                                 I_CmsExtractionResult extractionResult,
                                                                 List<CmsProperty> properties,
                                                                 List<CmsProperty> propertiesSearched)
Extends the given document by the mappings for the given field.

Parameters:
document - the document to extend
fieldConfig - the field to create the mappings for
cms - the OpenCms context used for building the search index
resource - the resource that is indexed
extractionResult - the plain text extraction result from the resource
properties - the list of all properties directly attached to the resource (not searched)
propertiesSearched - the list of all searched properties of the resource
Returns:
the document extended by the mappings for the given field

appendFieldMappings

protected org.apache.lucene.document.Document appendFieldMappings(org.apache.lucene.document.Document document,
                                                                  CmsObject cms,
                                                                  CmsResource resource,
                                                                  I_CmsExtractionResult extractionResult,
                                                                  List<CmsProperty> properties,
                                                                  List<CmsProperty> propertiesSearched)
Extends the given document by the configured field mappings.

Parameters:
document - the document to extend
cms - the OpenCms context used for building the search index
resource - the resource that is indexed
extractionResult - the plain text extraction result from the resource
properties - the list of all properties directly attached to the resource (not searched)
propertiesSearched - the list of all searched properties of the resource
Returns:
the document extended by the configured field mappings

appendPath

protected org.apache.lucene.document.Document appendPath(org.apache.lucene.document.Document document,
                                                         CmsObject cms,
                                                         CmsResource resource,
                                                         I_CmsExtractionResult extractionResult,
                                                         List<CmsProperty> properties,
                                                         List<CmsProperty> propertiesSearched)
Extends the given document by fields for VFS path lookup.

Parameters:
document - the document to extend
cms - the OpenCms context used for building the search index
resource - the resource that is indexed
extractionResult - the plain text extraction result from the resource
properties - the list of all properties directly attached to the resource (not searched)
propertiesSearched - the list of all searched properties of the resource
Returns:
the document extended by fields for VFS path lookup

appendType

protected org.apache.lucene.document.Document appendType(org.apache.lucene.document.Document document,
                                                         CmsObject cms,
                                                         CmsResource resource,
                                                         I_CmsExtractionResult extractionResult,
                                                         List<CmsProperty> properties,
                                                         List<CmsProperty> propertiesSearched)
                                                  throws CmsLoaderException
Extends the given document by a field that contains the resource type name.

Parameters:
document - the document to extend
cms - the OpenCms context used for building the search index
resource - the resource that is indexed
extractionResult - the plain text extraction result from the resource
properties - the list of all properties directly attached to the resource (not searched)
propertiesSearched - the list of all searched properties of the resource
Returns:
the document extended by a field that contains the resource type name
Throws:
CmsLoaderException - in case of errors identifying the resource type name

getAnalyzerForDefaultFields

protected org.apache.lucene.analysis.Analyzer getAnalyzerForDefaultFields(org.apache.lucene.analysis.Analyzer analyzer)
Returns an analyzer that wraps the given base analyzer with special analyzers required for the hard coded document fields.

Parameters:
analyzer - the base analyzer to wrap
Returns:
an analyzer that wraps the given base analyzer for the hard coded document fields
See Also:
getAnalyzer(Analyzer)

setBoost

protected org.apache.lucene.document.Document setBoost(org.apache.lucene.document.Document document,
                                                       CmsObject cms,
                                                       CmsResource resource,
                                                       I_CmsExtractionResult extractionResult,
                                                       List<CmsProperty> properties,
                                                       List<CmsProperty> propertiesSearched)
Extends the given document with a boost factor.

Parameters:
document - the document to extend
cms - the OpenCms context used for building the search index
resource - the resource that is indexed
extractionResult - the plain text extraction result from the resource
properties - the list of all properties directly attached to the resource (not searched)
propertiesSearched - the list of all searched properties of the resource
Returns:
the document extended by a boost factor