001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://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, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://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.fields;
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;
035import org.opencms.search.documents.I_CmsDocumentFactory;
036import org.opencms.search.extractors.I_CmsExtractionResult;
037
038import java.io.Serializable;
039import java.util.List;
040import java.util.Map;
041
042import org.apache.solr.uninverting.UninvertingReader.Type;
043
044/**
045 * Interface for search field configurations used by {@link org.opencms.search.I_CmsSearchIndex} and configured in the
046 * opencms-search.xml (see {@link org.opencms.configuration.CmsSearchConfiguration}).
047 */
048public interface I_CmsSearchFieldConfiguration extends Comparable<I_CmsSearchFieldConfiguration>, Serializable {
049
050    /**
051     * Adds a field to this search field configuration.<p>
052     *
053     * @param field the field to add
054     */
055    void addField(CmsSearchField field);
056
057    /** To allow sorting on a field (without docvalues) the field must be added to the map
058     *  given to {@link org.apache.solr.uninverting.UninvertingReader#wrap(org.apache.lucene.index.DirectoryReader, Map)}.
059     *  The method adds the configured fields.
060     * @param uninvertingMap the map to which the fields are added.
061     */
062    void addUninvertingMappings(Map<String, Type> uninvertingMap);
063
064    /**
065     * Creates the document to index.
066     *
067     * The structure of the document depends on the concrete field configuration, the provided VFS resource, search index and extracted content.<p>
068     *
069     * The method is typically triggered by {@link I_CmsDocumentFactory#createDocument(CmsObject, CmsResource, I_CmsSearchIndex)} to create the document.<p>
070     *
071     * @param cms the OpenCms user context used to access the OpenCms VFS
072     * @param resource the resource to create the document from
073     * @param index the search index to create the document for
074     * @param extractionResult the plain text content and additional information extracted from the document
075     *
076     * @return the document to index for the given VFS resource and the given search index
077     *
078     * @throws CmsException if something goes wrong
079     */
080    I_CmsSearchDocument createDocument(
081        CmsObject cms,
082        CmsResource resource,
083        I_CmsSearchIndex index,
084        I_CmsExtractionResult extractionResult)
085    throws CmsException;
086
087    /**
088     * Returns the description of this field configuration.<p>
089     *
090     * @return the description of this field configuration
091     */
092    String getDescription();
093
094    /**
095     * Returns the configured {@link CmsSearchField} instance with the given name.<p>
096     *
097     * @return the configured {@link CmsSearchField} instance with the given name
098     */
099    List<CmsSearchField> getFields();
100
101    /**
102     * Returns the name of this field configuration.<p>
103     *
104     * @return the name of this field configuration
105     */
106    String getName();
107
108    /**
109     * Initializes this field configuration.<p>
110     */
111    void init();
112
113    /**
114     * Sets the description of this field configuration.<p>
115     *
116     * @param description the description to set
117     */
118    void setDescription(String description);
119
120    /**
121     * Sets the name of this field configuration.<p>
122     *
123     * @param name the name to set
124     */
125    void setName(String name);
126
127}