org.opencms.search.galleries
Class CmsGalleryDocumentXmlContent

java.lang.Object
  extended by org.opencms.search.documents.A_CmsVfsDocument
      extended by org.opencms.search.documents.CmsDocumentXmlContent
          extended by org.opencms.search.galleries.CmsGalleryDocumentXmlContent
All Implemented Interfaces:
I_CmsDocumentFactory, I_CmsSearchExtractor

public class CmsGalleryDocumentXmlContent
extends CmsDocumentXmlContent

Special document text extraction factory for the gallery index that creates multiple fields for the content in all the languages available in an XML content.

Since:
8.0.0

Field Summary
 
Fields inherited from class org.opencms.search.documents.A_CmsVfsDocument
m_name
 
Constructor Summary
CmsGalleryDocumentXmlContent(java.lang.String name)
          Creates a new instance of this Lucene document factory.
 
Method Summary
 I_CmsSearchDocument createDocument(CmsObject cms, CmsResource resource, CmsSearchIndex index)
          Generates a new lucene document instance from contents of the given resource for the provided index.
 I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, CmsSearchIndex index)
          Returns the raw text content of a given VFS resource of type CmsResourceTypeXmlContent.
protected  java.util.List<java.util.Locale> getLocalesToStore(A_CmsXmlDocument content)
          Gets the locales which should be stored in the locale field of the document for the given content.
protected  java.util.List<java.util.Locale> getTargetLocalesForField(A_CmsXmlDocument xmlContent, java.lang.String fieldName, java.util.Locale sourceLocale)
          Returns the locales which the given field should be written to in the document.
protected  boolean isGroup(A_CmsXmlDocument content)
          Helper method to check whether the content is an element group.
 boolean isLocaleDependend()
          Gallery index content is stored in multiple languages, so the result is NOT locale dependent.
protected  void putMappingValue(A_CmsXmlDocument xmlContent, java.lang.String fieldName, java.util.Locale sourceLocale, java.util.Map<java.lang.String,java.lang.String> items, java.lang.String value)
          Adds the given value to the document items for all target locales.
 
Methods inherited from class org.opencms.search.documents.CmsDocumentXmlContent
getDocumentKeys, isUsingCache
 
Methods inherited from class org.opencms.search.documents.A_CmsVfsDocument
getCache, getDocumentKey, getName, logContentExtraction, readFile, setCache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsGalleryDocumentXmlContent

public CmsGalleryDocumentXmlContent(java.lang.String name)
Creates a new instance of this Lucene document factory.

Parameters:
name - name of the document type
Method Detail

createDocument

public I_CmsSearchDocument createDocument(CmsObject cms,
                                          CmsResource resource,
                                          CmsSearchIndex index)
                                   throws CmsException
Generates a new lucene document instance from contents of the given resource for the provided index.

For gallery document generators, we never check for CmsSearchIndex.isExtractingContent() since all these classes are assumed to be written with optimizations special to gallery search indexing anyway.

Specified by:
createDocument in interface I_CmsDocumentFactory
Overrides:
createDocument in class CmsDocumentXmlContent
Parameters:
cms - the OpenCms user context used to access the OpenCms VFS
resource - the search index resource to create the Lucene document from
index - the search index to create the Document for
Returns:
the Search Document for the given index resource and the given search index
Throws:
CmsException - if something goes wrong
See Also:
CmsSearchFieldConfiguration.createDocument(CmsObject, CmsResource, CmsSearchIndex, I_CmsExtractionResult), I_CmsDocumentFactory.createDocument(CmsObject, CmsResource, CmsSearchIndex)

extractContent

public I_CmsExtractionResult extractContent(CmsObject cms,
                                            CmsResource resource,
                                            CmsSearchIndex index)
                                     throws CmsException
Returns the raw text content of a given VFS resource of type CmsResourceTypeXmlContent.

All XML nodes from the content for all locales will be stored separately in the item map which you can access using CmsExtractionResult.getContentItems(). The XML elements will be accessible using their xpath. The xpath will start with the locale and have the form like for example de/Text[1] or en/Nested[1]/Text[1].

Specified by:
extractContent in interface I_CmsSearchExtractor
Overrides:
extractContent in class CmsDocumentXmlContent
Parameters:
cms - the cms object
resource - the resource to extract the content from
index - the index to extract the content for
Returns:
the extracted content of the resource
Throws:
CmsException - if something goes wrong
See Also:
I_CmsSearchExtractor.extractContent(CmsObject, CmsResource, CmsSearchIndex)

isLocaleDependend

public boolean isLocaleDependend()
Gallery index content is stored in multiple languages, so the result is NOT locale dependent.

Specified by:
isLocaleDependend in interface I_CmsDocumentFactory
Overrides:
isLocaleDependend in class CmsDocumentXmlContent
Returns:
true if this document factory is locale depended
See Also:
CmsDocumentXmlContent.isLocaleDependend()

getLocalesToStore

protected java.util.List<java.util.Locale> getLocalesToStore(A_CmsXmlDocument content)
Gets the locales which should be stored in the locale field of the document for the given content.

Parameters:
content - the XML content
Returns:
the list of locales for the locale field

getTargetLocalesForField

protected java.util.List<java.util.Locale> getTargetLocalesForField(A_CmsXmlDocument xmlContent,
                                                                    java.lang.String fieldName,
                                                                    java.util.Locale sourceLocale)
Returns the locales which the given field should be written to in the document.

Parameters:
xmlContent - the XML content
fieldName - the field name
sourceLocale - the source locale
Returns:
the list of locales to which the field should be written

isGroup

protected boolean isGroup(A_CmsXmlDocument content)
Helper method to check whether the content is an element group.

Parameters:
content - the content to check
Returns:
true if the content is an element group

putMappingValue

protected void putMappingValue(A_CmsXmlDocument xmlContent,
                               java.lang.String fieldName,
                               java.util.Locale sourceLocale,
                               java.util.Map<java.lang.String,java.lang.String> items,
                               java.lang.String value)
Adds the given value to the document items for all target locales.

Parameters:
xmlContent - the XML content
fieldName - the field name
sourceLocale - the source locale
items - the document items
value - the value to put