001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.search.documents; 029 030import org.opencms.file.CmsObject; 031import org.opencms.file.CmsResource; 032import org.opencms.main.CmsException; 033import org.opencms.search.I_CmsSearchDocument; 034import org.opencms.search.I_CmsSearchIndex; 035 036import java.util.List; 037 038/** 039 * Used to create index Lucene Documents for OpenCms resources, 040 * controls the text extraction algorithm used for a specific OpenCms resource type / MIME type combination.<p> 041 * 042 * The configuration of the search index is defined in <code>opencms-search.xml</code>. 043 * There you can associate a combintion of OpenCms resource types and MIME types to an instance 044 * of this factory. This rather complex configuration is required because only the combination of 045 * OpenCms resource type and MIME type can decide what to use for search indexing. 046 * For example, if the OpenCms resource type is <code>plain</code>, 047 * the extraction algorithm for MIME types <code>.html</code> and <code>.txt</code> must be different. 048 * On the other hand, the MIME type <code>.html</code> in OpenCms can be almost any resource type, 049 * like <code>xmlpage</code>, <code>xmlcontent</code> or even <code>jsp</code>.<p> 050 * 051 * @since 6.0.0 052 */ 053public interface I_CmsDocumentFactory extends I_CmsSearchExtractor { 054 055 default void addConfigurationParameter(String key, String value) { 056 057 // do noting 058 } 059 060 /** 061 * Creates the Lucene Document for the given VFS resource and the given search index.<p> 062 * 063 * This triggers the indexing process for the given VFS resource according to the configuration 064 * of the provided index.<p> 065 * 066 * The provided index resource contains the basic contents to index. 067 * The provided search index contains the configuration what to index, such as the locale and 068 * possible special field mappings.<p> 069 * 070 * @param cms the OpenCms user context used to access the OpenCms VFS 071 * @param resource the search index resource to create the Lucene document from 072 * @param index the search index to create the Document for 073 * 074 * @return the Search Document for the given index resource and the given search index 075 * 076 * @throws CmsException if something goes wrong 077 * 078 * @see org.opencms.search.fields.CmsSearchFieldConfiguration#createDocument(CmsObject, CmsResource, I_CmsSearchIndex, org.opencms.search.extractors.I_CmsExtractionResult) 079 */ 080 I_CmsSearchDocument createDocument(CmsObject cms, CmsResource resource, I_CmsSearchIndex index) throws CmsException; 081 082 /** 083 * Returns the disk based cache used to store the raw extraction results.<p> 084 * 085 * In case <code>null</code> is returned, then result caching is not supported for this factory.<p> 086 * 087 * @return the disk based cache used to store the raw extraction results 088 */ 089 CmsExtractionResultCache getCache(); 090 091 /** 092 * Returns the list of accepted keys for the resource types that can be indexed using this document factory.<p> 093 * 094 * The result List contains String objects. 095 * This String is later matched against {@link A_CmsVfsDocument#getDocumentKey(String, String)} to find 096 * the corrospondig {@link I_CmsDocumentFactory} for a resource to index.<p> 097 * 098 * The list of accepted resource types may contain a catch-all entry "*"; 099 * in this case, a list for all possible resource types is returned, 100 * calculated by a logic depending on the document handler class.<p> 101 * 102 * @param resourceTypes list of accepted resource types 103 * @param mimeTypes list of accepted mime types 104 * 105 * @return the list of accepted keys for the resource types that can be indexed using this document factory (String objects) 106 * 107 * @throws CmsException if something goes wrong 108 */ 109 List<String> getDocumentKeys(List<String> resourceTypes, List<String> mimeTypes) throws CmsException; 110 111 /** 112 * Returns the name of this document type factory.<p> 113 * 114 * @return the name of this document type factory 115 */ 116 String getName(); 117 118 /** 119 * Returns <code>true</code> if this document factory is locale depended.<p> 120 * 121 * @return <code>true</code> if this document factory is locale depended 122 */ 123 boolean isLocaleDependend(); 124 125 /** 126 * Returns <code>true</code> if the extraction result dependent on the resources content itself, i.e., has not to be re-extracted if the content date is unchanged.<p> 127 * 128 * @return <code>true</code> if the extraction result dependent on the resources content itself, i.e., has not to be re-extracted if the content date is unchanged. 129 */ 130 default boolean isOnlyDependentOnContent() { 131 132 return true; 133 } 134 135 /** 136 * Returns <code>true</code> if result caching is supported for this factory.<p> 137 * 138 * @return <code>true</code> if result caching is supported for this factory 139 */ 140 boolean isUsingCache(); 141 142 /** 143 * Sets the disk based cache used to store the raw extraction results.<p> 144 * 145 * This should only be used for factories where {@link #isUsingCache()} returns <code>true</code>.<p> 146 * 147 * @param cache the disk based cache used to store the raw extraction results 148 */ 149 void setCache(CmsExtractionResultCache cache); 150}