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 License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, 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;
029
030import org.opencms.relations.CmsCategory;
031import org.opencms.search.fields.CmsSearchField;
032
033import java.util.Collection;
034import java.util.Date;
035import java.util.List;
036import java.util.Locale;
037
038/**
039 * The interface for search documents.<p>
040 */
041public interface I_CmsSearchDocument {
042
043    /** Value for "high" search priority. */
044    String SEARCH_PRIORITY_HIGH_VALUE = "high";
045
046    /** Value for "low" search priority. */
047    String SEARCH_PRIORITY_LOW_VALUE = "low";
048
049    /** Value for "maximum" search priority. */
050    String SEARCH_PRIORITY_MAX_VALUE = "max";
051
052    /** Value for "normal" search priority. */
053    String SEARCH_PRIORITY_NORMAL_VALUE = "normal";
054
055    /** The VFS prefix for document keys. */
056    String VFS_DOCUMENT_KEY_PREFIX = "VFS";
057
058    /**
059     * Adds the list of the given categories to this document.<p>
060     *
061     * @param categories the categories to add
062     */
063    void addCategoryField(List<CmsCategory> categories);
064
065    /**
066     * Adds the given content byte array to this document.<p>
067     *
068     * @param content the content to add
069     */
070    void addContentField(byte[] content);
071
072    /**
073     * Adds the locales of the content to this document.<p>
074     *
075     * @param locales the locales of the content
076     */
077    void addContentLocales(Collection<Locale> locales);
078
079    /**
080     * Puts the given date into the field with the given name.<p>
081     *
082     * @param name the name to put the date in
083     * @param date the date to pu into the field
084     * @param analyzed <code>true</code> if the inserted value should be analyzable
085     */
086    void addDateField(String name, long date, boolean analyzed);
087
088    /**
089     * Adds the given file size as field to this document.<p>
090     *
091     * @param length the length
092     */
093    void addFileSizeField(int length);
094
095    /**
096     * Puts the given path into this document.<p>
097     *
098     * @param rootPath the given path into this document
099     */
100    void addPathField(String rootPath);
101
102    /**
103     * Adds the locales of the resource to this document.<p>
104     *
105     * @param locales the locales of the resource
106     */
107    void addResourceLocales(Collection<Locale> locales);
108
109    /**
110     * Puts the given root path into its default field.<p>
111     *
112     * @param rootPath the root path to put into the field
113     */
114    void addRootPathField(String rootPath);
115
116    /**
117     * Adds a dynamic search field to the index.<p>
118     *
119     * @param field the field
120     * @param value the value
121     */
122    void addSearchField(CmsSearchField field, String value);
123
124    /**
125     * Adds the suffix field to the document. This field should contain the resource suffix.<p>
126     *
127     * <b>Example</b><br/>
128     * <code>'html' for a file named 'article.html'</code>
129     *
130     * @param suffix the suffix to add
131     */
132    void addSuffixField(String suffix);
133
134    /**
135     * Adds the resource type to this document.<p>
136     * @param type the resource type name.
137     */
138    void addTypeField(String type);
139
140    /**
141     * Returns the content blob of this document.<p>
142     *
143     * @return the content blob
144     */
145    byte[] getContentBlob();
146
147    /**
148     * Returns the concrete document as Object to be cast if necessary.<p>
149     *
150     * @return the document as Object
151     */
152    Object getDocument();
153
154    /**
155     * Returns all field names of this document.<p>
156     *
157     * @return the field names
158     */
159    List<String> getFieldNames();
160
161    /**
162     * Tries to return the value of the field for the given name as Date,
163     * <code>null</code> if the field is empty or if the field is not of the type date.<p>
164     *
165     * @param fieldName the name of the field to get the Date value for
166     *
167     * @return the date or <code>null</code>
168     */
169    Date getFieldValueAsDate(String fieldName);
170
171    /**
172     * Returns the value of the field for the given name as String.<p>
173     *
174     * @param fieldName the name of the field to get the String value for
175     *
176     * @return the String value or <code>null</code> if empty
177     */
178    String getFieldValueAsString(String fieldName);
179
180    /**
181     * Returns the values of a multi-valued field as list of strings.
182     * @param fieldName the name of the multivalued field to get the values from.
183     * @return the values of a multi-valued field as list of strings.
184     */
185    List<String> getMultivaluedFieldAsStringList(String fieldName);
186
187    /**
188     * Returns the root path of the referenced VFS resource of this document.<p>
189     *
190     * @return the root path
191     */
192    String getPath();
193
194    /**
195     * Returns the score for this document.<p>
196     *
197     * @return the score
198     */
199    float getScore();
200
201    /**
202     * Returns the resource type of the referenced VFS resource of this document.<p>
203     *
204     * @return the type
205     */
206    String getType();
207
208    /**
209     * Sets the score for this document.<p>
210     *
211     * @param score the score
212     */
213    void setScore(float score);
214
215}