org.opencms.search.fields
Class CmsSearchField

java.lang.Object
  extended by org.opencms.search.fields.CmsSearchField

public class CmsSearchField
extends java.lang.Object

An individual field configuration in a search index.

Since:
7.0.0
Version:
$Revision: 1.15 $
Author:
Alexander Kandzior

Field Summary
static float BOOST_DEFAULT
          Th default boost factor (1.0), used in case no boost has been set for a field.
static java.lang.String FIELD_CATEGORY
          Name of the field that contains the (optional) category of the document (hardcoded).
static java.lang.String FIELD_CONTENT
          Name of the field that usually contains the complete content of the document (optional).
static java.lang.String FIELD_CONTENT_BLOB
          Name of the field that contains the complete extracted content of the document as serialized object (hardcoded).
static java.lang.String FIELD_DATE_CONTENT
          Name of the field that contains the document content date (hardcoded).
static java.lang.String FIELD_DATE_CREATED
          Name of the field that contains the document creation date (hardcoded).
static java.lang.String FIELD_DATE_LASTMODIFIED
          Name of the field that contains the document last modification date (hardcoded).
static java.lang.String FIELD_DESCRIPTION
          Name of the field that usually contains the value of the "Description" property of the document (optional).
static java.lang.String FIELD_KEYWORDS
          Name of the field that usually contains the value of the "Keywords" property of the document (optional).
static java.lang.String FIELD_META
          Name of the field that usually combines all document "meta" information, that is the values of the "Title", "Keywords" and "Description" properties (optional).
static java.lang.String FIELD_PARENT_FOLDERS
          Name of the field that contains all VFS parent folders of a document (hardcoded).
static java.lang.String FIELD_PATH
          Name of the field that contains the document root path in the VFS (hardcoded).
static java.lang.String FIELD_PRIORITY
          Name of the field that contains the (optional) document priority, which can be used to boost the document in the result list (hardcoded).
static java.lang.String FIELD_TITLE
          Name of the field that usually contains the value of the "Title" property of the document as a keyword used for sorting and also for retrieving the title text (optional).
static java.lang.String FIELD_TITLE_UNSTORED
          Name of the field that usually contains the value of the "Title" property of the document in an analyzed form used for searching in the title (optional).
static java.lang.String FIELD_TYPE
          Name of the field that contains the type of the document.
static java.lang.String IGNORE_DISPLAY_NAME
          Value of m_displayName if field should not be displayed.
static java.lang.String LUCENE_ANALYZER
          Prefix for Lucene default analyzers package (org.apache.lucene.analysis.
static java.lang.String STR_COMPRESS
          Constant for the "compress" index setting.
static java.lang.String STR_NO
          Constant for the "no" index setting.
static java.lang.String STR_TOKENIZED
          Constant for the "tokenized" index setting.
static java.lang.String STR_UN_TOKENIZED
          Constant for the "untokenized" index setting.
static java.lang.String STR_YES
          Constant for the "yes" index setting.
 
Constructor Summary
CmsSearchField()
          Creates a new search field configuration.
CmsSearchField(java.lang.String name, java.lang.String displayName, boolean isStored, boolean isIndexed)
          Creates a new search field configuration.
CmsSearchField(java.lang.String name, java.lang.String displayName, boolean isStored, boolean isCompressed, boolean isIndexed, boolean isTokenized, boolean isInExcerpt, org.apache.lucene.analysis.Analyzer analyzer, float boost, java.lang.String defaultValue)
          Creates a new search field configuration.
CmsSearchField(java.lang.String name, java.lang.String displayName, boolean isStored, boolean isIndexed, boolean isTokenized, boolean isInExcerpt, float boost, java.lang.String defaultValue)
          Creates a new search field configuration.
 
Method Summary
 void addMapping(CmsSearchFieldMapping mapping)
          Adds a new field mapping to the internal list of mappings.
 org.apache.lucene.document.Field createField(java.lang.String content)
          Creates a Lucene field from the configuration and the provided content.
 boolean equals(java.lang.Object obj)
          Two fields are equal if the name of the Lucene field is equal.
 org.apache.lucene.analysis.Analyzer getAnalyzer()
          Returns the analyzer used for this field.
 float getBoost()
          Returns the boost factor of this field.
 java.lang.String getBoostDisplay()
          Returns the boost factor of thsi field as String value for display use.
 java.lang.String getDefaultValue()
          Returns the default value to use if no content for this field was collected.
 java.lang.String getDisplayName()
          Returns the display name of the field.
 java.lang.String getDisplayNameForConfiguration()
          Returns the displayNameForConfiguration.
 java.lang.String getIndexed()
          Returns the String value state of this field if it is indexed (and possibly tokenized) in the Lucene index.
 java.util.List<CmsSearchFieldMapping> getMappings()
          Returns the mappings for this field.
 java.lang.String getName()
          Returns the name of this field in the Lucene search index.
 int hashCode()
          The hash code for a field is based only on the field name.
 boolean isCompressed()
          Returns true if the content of this field is compressed.
 boolean isDisplayed()
          Returns true if the field should be displayed.
 boolean isIndexed()
          Returns the indexed.
 boolean isInExcerpt()
          Returns true if this fields content is used in the search result excerpt.
 boolean isInExcerptAndStored()
          Returns true if this fields content is used in the search result excerpt.
 boolean isStored()
          Returns true if the content of this field is stored in the Lucene index.
 boolean isTokenized()
          Returns true if the content of this field is tokenized in the Lucene index.
 boolean isTokenizedAndIndexed()
          Returns true if the content of this field is tokenized in the Lucene index.
 void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
          Sets the analyzer used for this field.
 void setAnalyzer(java.lang.String analyzer)
          Sets the analyzer used for this field.
 void setBoost(float boost)
          Sets the boost factor for this field.
 void setBoost(java.lang.String boost)
          Sets the boost factor for this field from a String value.
 void setBoostDisplay(java.lang.String boost)
          Sets the boost factor of this field (only for display use).
 void setCompressed(boolean compressed)
          Controls if this field value will be stored compressed or not.
 void setDefaultValue(java.lang.String defaultValue)
          Sets the default value to use if no content for this field was collected.
 void setDisplayed(boolean displayed)
          Controls if the field is displayed or not.
 void setDisplayName(java.lang.String displayName)
          Sets the display name.
 void setDisplayNameForConfiguration(java.lang.String displayNameForConfiguration)
          Sets the displayNameForConfiguration.
 void setIndexed(boolean indexed)
          Controls if the content of this field is indexed (and possibly tokenized) in the Lucene index.
 void setIndexed(java.lang.String indexed)
          Controls if the content of this field is indexed (and possibly tokenized) in the Lucene index from a String parameter.
 void setInExcerpt(boolean excerpt)
          Controls if this fields content is used in the search result excerpt.
 void setInExcerpt(java.lang.String excerpt)
          Controls if this fields content is used in the search result excerpt.
 void setName(java.lang.String name)
          Sets the name of this field in the Lucene search index.
 void setStored(boolean stored)
          Controls if the content of this field is stored in the Lucene index.
 void setStored(java.lang.String stored)
          Controls if the content of this field is stored in the Lucene index from a String parameter.
 void setTokenized(boolean tokenized)
          Controls if the content of this field is tokenized in the Lucene index.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOOST_DEFAULT

public static final float BOOST_DEFAULT
Th default boost factor (1.0), used in case no boost has been set for a field.

See Also:
Constant Field Values

FIELD_CATEGORY

public static final java.lang.String FIELD_CATEGORY
Name of the field that contains the (optional) category of the document (hardcoded).

See Also:
Constant Field Values

FIELD_CONTENT

public static final java.lang.String FIELD_CONTENT
Name of the field that usually contains the complete content of the document (optional).

See Also:
Constant Field Values

FIELD_CONTENT_BLOB

public static final java.lang.String FIELD_CONTENT_BLOB
Name of the field that contains the complete extracted content of the document as serialized object (hardcoded).

See Also:
Constant Field Values

FIELD_DATE_CONTENT

public static final java.lang.String FIELD_DATE_CONTENT
Name of the field that contains the document content date (hardcoded).

See Also:
Constant Field Values

FIELD_DATE_CREATED

public static final java.lang.String FIELD_DATE_CREATED
Name of the field that contains the document creation date (hardcoded).

See Also:
Constant Field Values

FIELD_DATE_LASTMODIFIED

public static final java.lang.String FIELD_DATE_LASTMODIFIED
Name of the field that contains the document last modification date (hardcoded).

See Also:
Constant Field Values

FIELD_DESCRIPTION

public static final java.lang.String FIELD_DESCRIPTION
Name of the field that usually contains the value of the "Description" property of the document (optional).

See Also:
Constant Field Values

FIELD_KEYWORDS

public static final java.lang.String FIELD_KEYWORDS
Name of the field that usually contains the value of the "Keywords" property of the document (optional).

See Also:
Constant Field Values

FIELD_META

public static final java.lang.String FIELD_META
Name of the field that usually combines all document "meta" information, that is the values of the "Title", "Keywords" and "Description" properties (optional).

See Also:
Constant Field Values

FIELD_PATH

public static final java.lang.String FIELD_PATH
Name of the field that contains the document root path in the VFS (hardcoded).

See Also:
Constant Field Values

FIELD_PRIORITY

public static final java.lang.String FIELD_PRIORITY
Name of the field that contains the (optional) document priority, which can be used to boost the document in the result list (hardcoded).

See Also:
Constant Field Values

FIELD_PARENT_FOLDERS

public static final java.lang.String FIELD_PARENT_FOLDERS
Name of the field that contains all VFS parent folders of a document (hardcoded).

See Also:
Constant Field Values

FIELD_TITLE

public static final java.lang.String FIELD_TITLE
Name of the field that usually contains the value of the "Title" property of the document as a keyword used for sorting and also for retrieving the title text (optional). Please note: This field should NOT be used for searching. Use FIELD_TITLE_UNSTORED instead.

See Also:
Constant Field Values

FIELD_TITLE_UNSTORED

public static final java.lang.String FIELD_TITLE_UNSTORED
Name of the field that usually contains the value of the "Title" property of the document in an analyzed form used for searching in the title (optional).

See Also:
Constant Field Values

FIELD_TYPE

public static final java.lang.String FIELD_TYPE
Name of the field that contains the type of the document.

See Also:
Constant Field Values

IGNORE_DISPLAY_NAME

public static final java.lang.String IGNORE_DISPLAY_NAME
Value of m_displayName if field should not be displayed.

See Also:
Constant Field Values

LUCENE_ANALYZER

public static final java.lang.String LUCENE_ANALYZER
Prefix for Lucene default analyzers package (org.apache.lucene.analysis.).

See Also:
Constant Field Values

STR_COMPRESS

public static final java.lang.String STR_COMPRESS
Constant for the "compress" index setting.

See Also:
Constant Field Values

STR_NO

public static final java.lang.String STR_NO
Constant for the "no" index setting.

See Also:
Constant Field Values

STR_TOKENIZED

public static final java.lang.String STR_TOKENIZED
Constant for the "tokenized" index setting.

See Also:
Constant Field Values

STR_UN_TOKENIZED

public static final java.lang.String STR_UN_TOKENIZED
Constant for the "untokenized" index setting.

See Also:
Constant Field Values

STR_YES

public static final java.lang.String STR_YES
Constant for the "yes" index setting.

See Also:
Constant Field Values
Constructor Detail

CmsSearchField

public CmsSearchField()
Creates a new search field configuration.


CmsSearchField

public CmsSearchField(java.lang.String name,
                      java.lang.String displayName,
                      boolean isStored,
                      boolean isIndexed)
Creates a new search field configuration.

The field will be tokenized if it is indexed. The field will not be in the excerpt. The boost value is the default, that is no special boost is used. There is no default value.

Parameters:
name - the name of the field, see setName(String)
displayName - the display name of this field, see setDisplayName(String)
isStored - controls if the field is stored and in the excerpt, see setStored(boolean)
isIndexed - controls if the field is indexed and tokenized, see setIndexed(boolean)

CmsSearchField

public CmsSearchField(java.lang.String name,
                      java.lang.String displayName,
                      boolean isStored,
                      boolean isCompressed,
                      boolean isIndexed,
                      boolean isTokenized,
                      boolean isInExcerpt,
                      org.apache.lucene.analysis.Analyzer analyzer,
                      float boost,
                      java.lang.String defaultValue)
Creates a new search field configuration.

Parameters:
name - the name of the field, see setName(String)
displayName - the display name of this field, see setDisplayName(String)
isStored - controls if the field is stored, see setStored(boolean)
isCompressed - controls if the filed is compressed, see setCompressed(boolean)
isIndexed - controls if the field is indexed, see setIndexed(boolean)
isTokenized - controls if the field is tokenized, see setStored(boolean)
isInExcerpt - controls if the field is in the excerpt, see isInExcerptAndStored()
analyzer - the Lucene analyzer to use for this field
boost - the boost factor for the field, see setBoost(float)
defaultValue - the default value for the field, see setDefaultValue(String)

CmsSearchField

public CmsSearchField(java.lang.String name,
                      java.lang.String displayName,
                      boolean isStored,
                      boolean isIndexed,
                      boolean isTokenized,
                      boolean isInExcerpt,
                      float boost,
                      java.lang.String defaultValue)
Creates a new search field configuration.

Parameters:
name - the name of the field, see setName(String)
displayName - the display name of this field, see setDisplayName(String)
isStored - controls if the field is stored, see setStored(boolean)
isIndexed - controls if the field is indexed, see setIndexed(boolean)
isTokenized - controls if the field is tokenized, see setStored(boolean)
isInExcerpt - controls if the field is in the excerpt, see isInExcerptAndStored()
boost - the boost factor for the field, see setBoost(float)
defaultValue - the default value for the field, see setDefaultValue(String)
Method Detail

addMapping

public void addMapping(CmsSearchFieldMapping mapping)
Adds a new field mapping to the internal list of mappings.

Parameters:
mapping - the mapping to add

createField

public org.apache.lucene.document.Field createField(java.lang.String content)
Creates a Lucene field from the configuration and the provided content.

If no valid content is provided (ie. the content is either null or only whitespace), then no field is created and null is returned.

Parameters:
content - the content to create the field with
Returns:
a Lucene field created from the configuration and the provided conten

equals

public boolean equals(java.lang.Object obj)
Two fields are equal if the name of the Lucene field is equal.

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

getAnalyzer

public org.apache.lucene.analysis.Analyzer getAnalyzer()
Returns the analyzer used for this field.

Returns:
the analyzer used for this field

getBoost

public float getBoost()
Returns the boost factor of this field.

The boost factor is a Lucene function that controls the "importance" of a field in the search result ranking. The default is 1.0. A lower boost factor will make the field less important for the result ranking, a higher value will make it more important.

Returns:
the boost factor of this field

getBoostDisplay

public java.lang.String getBoostDisplay()
Returns the boost factor of thsi field as String value for display use.

Returns:
the boost factor of thsi field as String value for display use

getDefaultValue

public java.lang.String getDefaultValue()
Returns the default value to use if no content for this field was collected.

In case no default is configured, null is returned.

Returns:
the default value to use if no content for this field was collected

getDisplayName

public java.lang.String getDisplayName()
Returns the display name of the field.

Returns:
the display name of the field

getDisplayNameForConfiguration

public java.lang.String getDisplayNameForConfiguration()
Returns the displayNameForConfiguration.

Returns:
the displayNameForConfiguration

getIndexed

public java.lang.String getIndexed()
Returns the String value state of this field if it is indexed (and possibly tokenized) in the Lucene index.

Returns:
the String value state of this field if it is indexed (and possibly tokenized) in the Lucene index
See Also:
isTokenizedAndIndexed(), isIndexed()

getMappings

public java.util.List<CmsSearchFieldMapping> getMappings()
Returns the mappings for this field.

Returns:
the mappings for this field

getName

public java.lang.String getName()
Returns the name of this field in the Lucene search index.

Returns:
the name of this field in the Lucene search index

hashCode

public int hashCode()
The hash code for a field is based only on the field name.

Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

isCompressed

public boolean isCompressed()
Returns true if the content of this field is compressed.

If the field is compressed, it must also be stored, this means isStored() will always return true for compressed fields.

Returns:
true if the content of this field is compressed

isDisplayed

public boolean isDisplayed()
Returns true if the field should be displayed.

Returns:
returns true if the field should be displayed otherwise false

isIndexed

public boolean isIndexed()
Returns the indexed.

Returns:
the indexed

isInExcerpt

public boolean isInExcerpt()
Returns true if this fields content is used in the search result excerpt.

Returns:
true if this fields content is used in the search result excerpt
See Also:
isStored()

isInExcerptAndStored

public boolean isInExcerptAndStored()
Returns true if this fields content is used in the search result excerpt.

A field can only be used in the excerpt if it is stored, see isStored().

Returns:
true if this fields content is used in the search result excerpt
See Also:
isStored()

isStored

public boolean isStored()
Returns true if the content of this field is stored in the Lucene index.

Please refer to the Lucene documentation about Field.Store for the concept behind stored and unstored fields.

Returns:
true if the content of this field is stored in the Lucene index
See Also:
isTokenizedAndIndexed()

isTokenized

public boolean isTokenized()
Returns true if the content of this field is tokenized in the Lucene index.

Please refer to the Lucene documentation about Field.Index for the concept behind tokenized and untokenized fields.

Returns:
true if the content of this field is tokenized in the Lucene index

isTokenizedAndIndexed

public boolean isTokenizedAndIndexed()
Returns true if the content of this field is tokenized in the Lucene index.

A field can only be tokenized if it is also indexed, see isIndexed().

Please refer to the Lucene documentation about Field.Index for the concept behind tokenized and untokenized fields.

Returns:
true if the content of this field is tokenized in the Lucene index
See Also:
isStored(), isIndexed()

setAnalyzer

public void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
Sets the analyzer used for this field.

Parameters:
analyzer - the analyzer to set

setAnalyzer

public void setAnalyzer(java.lang.String analyzer)
                 throws java.lang.Exception
Sets the analyzer used for this field.

The parameter must be a name of a class the implements the Lucene Analyzer interface.

Parameters:
analyzer - the analyzer class name to set
Throws:
java.lang.Exception - in case of problems creating the analyzer class instance

setBoost

public void setBoost(float boost)
Sets the boost factor for this field.

The boost factor is a Lucene function that controls the "importance" of a field in the search result ranking. The default is 1.0. A lower boost factor will make the field less important for the result ranking, a higher value will make it more important.

Use with caution: You should only use this if you fully understand the concept behind Lucene boost factors. Otherwise it is likley that your result rankings will be worse then with the default values.

Parameters:
boost - the boost factor to set

setBoost

public void setBoost(java.lang.String boost)
Sets the boost factor for this field from a String value.

Parameters:
boost - the boost factor to set
See Also:
setBoost(float)

setBoostDisplay

public void setBoostDisplay(java.lang.String boost)
Sets the boost factor of this field (only for display use).

Parameters:
boost - the boost factor to set
See Also:
setBoost(String)

setCompressed

public void setCompressed(boolean compressed)
Controls if this field value will be stored compressed or not.

If this is set to true, the value for isStored() will also be set to true, since compressed fields are always stored.

Parameters:
compressed - if true, the field value will be stored compressed

setDefaultValue

public void setDefaultValue(java.lang.String defaultValue)
Sets the default value to use if no content for this field was collected.

Parameters:
defaultValue - the default value to set

setDisplayed

public void setDisplayed(boolean displayed)
Controls if the field is displayed or not.

Parameters:
displayed - if true the field is displayed

setDisplayName

public void setDisplayName(java.lang.String displayName)
Sets the display name. If the given name equals IGNORE_DISPLAY_NAME the field is not displayed.

Parameters:
displayName - the display name to set

setDisplayNameForConfiguration

public void setDisplayNameForConfiguration(java.lang.String displayNameForConfiguration)
Sets the displayNameForConfiguration.

Parameters:
displayNameForConfiguration - the displayNameForConfiguration to set

setIndexed

public void setIndexed(boolean indexed)
Controls if the content of this field is indexed (and possibly tokenized) in the Lucene index.

Parameters:
indexed - the indexed to set
See Also:
setTokenized(boolean)

setIndexed

public void setIndexed(java.lang.String indexed)
Controls if the content of this field is indexed (and possibly tokenized) in the Lucene index from a String parameter.

This sets the values for isIndexed() as well as isTokenizedAndIndexed().

The parameter can have the following values:

Parameters:
indexed - the index setting to use
See Also:
setIndexed(boolean), setTokenized(boolean)

setInExcerpt

public void setInExcerpt(boolean excerpt)
Controls if this fields content is used in the search result excerpt.

Parameters:
excerpt - if true, then this fields content is used in the search excerpt

setInExcerpt

public void setInExcerpt(java.lang.String excerpt)
Controls if this fields content is used in the search result excerpt.

Parameters:
excerpt - if "true", then this fields content is used in the search excerpt
See Also:
setInExcerpt(boolean)

setName

public void setName(java.lang.String name)
Sets the name of this field in the Lucene search index.

Parameters:
name - the name to set

setStored

public void setStored(boolean stored)
Controls if the content of this field is stored in the Lucene index.

Please refer to the Lucene documentation about Field.Store for the concept behind stored and unstored fields.

Parameters:
stored - if true, then the field content is stored
See Also:
setTokenized(boolean)

setStored

public void setStored(java.lang.String stored)
Controls if the content of this field is stored in the Lucene index from a String parameter.

Parameters:
stored - if "true", then the field content is stored
See Also:
setStored(boolean)

setTokenized

public void setTokenized(boolean tokenized)
Controls if the content of this field is tokenized in the Lucene index.

Please refer to the Lucene documentation about Field.Index for the concept behind tokenized and untokenized fields.

Parameters:
tokenized - if true, then the field content is tokenized
See Also:
setStored(boolean)