1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.search.solr.internal.api

File FieldUtils.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

6
10
3
1
375
79
6
0.6
3.33
3
2

Classes

Class Line # Actions
FieldUtils 38 10 0% 6 1
0.9473684494.7%
 

Contributing tests

This file is covered by 12 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.search.solr.internal.api;
21   
22    import java.util.Locale;
23   
24    /**
25    * Contains constants naming the Solr/Lucene index fields used by this module for indexing entities. Also contains
26    * additional constants used for composing field names on multilingual fields.
27    * <p>
28    * A multilingual and virtual/alias field, is not stored in the index with the specified name. It is only used at query
29    * time and it is expanded automatically to the actual fields from the index.
30    * <p>
31    * Example: "title" becomes "title_ | title_en | title_ro | title_fr | etc..."
32    * <p>
33    * <b>Note</b>: When indexing a field, the actual field name must be used instead of the virtual field name.
34    *
35    * @version $Id: a09fdf7f572527e2bc756e8293df5fbd7e00bf86 $
36    * @since 5.1M2
37    */
 
38    public final class FieldUtils
39    {
40    /**
41    * The suffix added to the fields used for sorting.
42    */
43    public static final String SORT_SUFFIX = "_sort";
44   
45    /**
46    * Keyword field, holds a string uniquely identifying a document across the index. This is used for finding old
47    * versions of a document to be indexed. The value format is wiki:Space.Page_locale .
48    */
49    public static final String ID = "id";
50   
51    /**
52    * Language of the document.
53    */
54    public static final String LANGUAGE = "language";
55   
56    /**
57    * The real/calculated locale of the document (the default locale in default document entry case).
58    */
59    public static final String LOCALE = "locale";
60   
61    /**
62    * Technical locale of the document (empty for the default document entry). Not indexed, mostly used to find the
63    * document in database.
64    */
65    public static final String DOCUMENT_LOCALE = "doclocale";
66   
67    /**
68    * The list of Locales covered by this entity. Dynamically determined from the list of enabled Locales and the
69    * various Locales of the associated wiki document.
70    */
71    public static final String LOCALES = "locales";
72   
73    /**
74    * Keyword field, holds the name of the virtual wiki a document belongs to.
75    */
76    public static final String WIKI = "wiki";
77   
78    /**
79    * The local reference of the space the document belongs to. For a document {@code A.B.C.Page} the value of this
80    * field is {@code A.B.C}. This field is analyzed and thus used for free text search.
81    *
82    * @deprecated since 7.2, use {@link #SPACES} instead; the problem with this field is that the standard tokenizer
83    * doesn't split around dots, and even if it did, it would also split around escaped dots (e.g.
84    * {@code A.B\.1.C}) which is not what we want.
85    * @see <a href="https://jira.xwiki.org/browse/XWIKI-12594">XWIKI-12594: The path of a nested document is not
86    * properly matched</a>
87    */
88    @Deprecated
89    public static final String SPACE = "space";
90   
91    /**
92    * The names of all the nested spaces the document belongs to. For a document {@code A.B.C.Page} the value of this
93    * field will be {@code ['A', 'B', 'C']}. This field is used for free text search.
94    */
95    public static final String SPACES = "spaces";
96   
97    /**
98    * The local space reference, unanalyzed and not stored, used for exact matching.
99    */
100    public static final String SPACE_EXACT = "space_exact";
101   
102    /**
103    * This field is used for hierarchical faceting on nested spaces (using 'facet.prefix'-based drill down). E.g. for a
104    * document A.B.C.Page this field will hold ['0/A.', '1/A.B.', '2/A.B.C.']
105    *
106    * @see <a href='https://wiki.apache.org/solr/HierarchicalFaceting'>Hierarchical Faceting</a>
107    * @since 7.2RC1
108    */
109    public static final String SPACE_FACET = "space_facet";
110   
111    /**
112    * This field is used to match descendant documents. A query such as {@code space_prefix:A.B} will match the
113    * documents from space A.B and all its descendants (like A.B.C). This is possible because this field holds the
114    * local references of all the ancestor spaces of a document (i.e. all the prefixes of the space reference). E.g.
115    * for a document A.B.C.Page this field will hold ['A', 'A.B', 'A.B.C']. As a consequence, searching for
116    * {@code space_prefix:A.B} will match A.B.C.Page
117    *
118    * @since 7.2RC1
119    */
120    public static final String SPACE_PREFIX = "space_prefix";
121   
122    /**
123    * Name of the document.
124    */
125    public static final String NAME = "name";
126   
127    /**
128    * Unanalyzed and not stored version of the document's name.
129    */
130    public static final String NAME_EXACT = "name_exact";
131   
132    /**
133    * FullName of the document (example: {@code Main.WebHome}).
134    */
135    public static final String FULLNAME = "fullname";
136   
137    /**
138    * Title of the document.
139    * <p>
140    * Note: Multilingual and virtual field.
141    */
142    public static final String TITLE = "title";
143   
144    /**
145    * Lowercased, unanalyzed and not stored version of the document's title, used for sorting.
146    */
147    public static final String TITLE_SORT = TITLE + SORT_SUFFIX;
148   
149    /**
150    * Version of the document (example: {@code 4.2}).
151    */
152    public static final String VERSION = "version";
153   
154    /**
155    * For storing the comment associated to the version.
156    * <p>
157    * Note: Multilingual and virtual field.
158    */
159    public static final String COMMENT = "comment";
160   
161    /**
162    * Type of a document. "DOCUMENT", "ATTACHMENT", "OBJECT" and "OBJECT_PROPERTY" are the used values corresponding to
163    * the values from {@link org.xwiki.model.EntityType}.
164    */
165    public static final String TYPE = "type";
166   
167    /**
168    * Used to index XClass names.
169    * <ul>
170    * <li>document: the type of objects a document has, e.g. [Blog.BlogPostClass, XWiki.TagClass, ..]</li>
171    * <li>object: the object type</li>
172    * <li>object property: the type of object this property belongs to</li>.
173    * </ul>
174    */
175    public static final String CLASS = "class";
176   
177    /**
178    * XWiki object number, only used for objects and properties.
179    */
180    public static final String NUMBER = "number";
181   
182    /**
183    * XWiki object content. Used by objects to index their properties and by documents to index all the properties of
184    * the contained objects.
185    * <p>
186    * Note: Multilingual and virtual field.
187    */
188    public static final String OBJECT_CONTENT = "objcontent";
189   
190    /**
191    * Last modifier.
192    */
193    public static final String AUTHOR = "author";
194   
195    /**
196    * Last modifier, in its display version (i.e., "first_name last_name").
197    */
198    public static final String AUTHOR_DISPLAY = "author_display";
199   
200    /**
201    * Lowercased, unanalyzed and not stored version of the document's last author display version, used for sorting.
202    */
203    public static final String AUTHOR_DISPLAY_SORT = AUTHOR_DISPLAY + SORT_SUFFIX;
204   
205    /**
206    * Creator of the document.
207    */
208    public static final String CREATOR = "creator";
209   
210    /**
211    * Creator of the document, in its display version (i.e., "first_name last_name").
212    */
213    public static final String CREATOR_DISPLAY = "creator_display";
214   
215    /**
216    * Date of last modification.
217    */
218    public static final String DATE = "date";
219   
220    /**
221    * Date of creation.
222    */
223    public static final String CREATIONDATE = "creationdate";
224   
225    /**
226    * Document hidden flag.
227    */
228    public static final String HIDDEN = "hidden";
229   
230    /**
231    * Document score, not an actual field. It's only computed at query time.
232    */
233    public static final String SCORE = "score";
234   
235    /**
236    * Fulltext plain rendered content.
237    * <p>
238    * Note: Multilingual and virtual field.
239    */
240    public static final String DOCUMENT_RENDERED_CONTENT = "doccontent";
241   
242    /**
243    * Raw content.
244    */
245    public static final String DOCUMENT_RAW_CONTENT = "doccontentraw";
246   
247    /**
248    * Attachment content.
249    * <p>
250    * Note: Multilingual and virtual field.
251    */
252    public static final String ATTACHMENT_CONTENT = "attcontent";
253   
254    /**
255    * Attachment version.
256    */
257    public static final String ATTACHMENT_VERSION = "attversion";
258   
259    /**
260    * The date when the last version of the attachment was uploaded.
261    */
262    public static final String ATTACHMENT_DATE = "attdate";
263   
264    /**
265    * Same as {@link #ATTACHMENT_DATE} but single valued so that it can be used for sorting.
266    */
267    public static final String ATTACHMENT_DATE_SORT = ATTACHMENT_DATE + SORT_SUFFIX;
268   
269    /**
270    * The size in bytes of the last version of the attachment.
271    */
272    public static final String ATTACHMENT_SIZE = "attsize";
273   
274    /**
275    * Same as {@link #ATTACHMENT_SIZE} but single valued so that it can be used for sorting.
276    */
277    public static final String ATTACHMENT_SIZE_SORT = ATTACHMENT_SIZE + SORT_SUFFIX;
278   
279    /**
280    * The user that uploaded the last version of the attachment.
281    */
282    public static final String ATTACHMENT_AUTHOR = "attauthor";
283   
284    /**
285    * The display name of the user that uploaded the last version of the attachment.
286    */
287    public static final String ATTACHMENT_AUTHOR_DISPLAY = ATTACHMENT_AUTHOR + "_display";
288   
289    /**
290    * Same as {@link #ATTACHMENT_AUTHOR_DISPLAY} but used for sorting.
291    */
292    public static final String ATTACHMENT_AUTHOR_DISPLAY_SORT = ATTACHMENT_AUTHOR_DISPLAY + SORT_SUFFIX;
293   
294    /**
295    * For storing mimetype of the attachments.
296    */
297    public static final String MIME_TYPE = "mimetype";
298   
299    /**
300    * Filename, only used for attachments.
301    */
302    public static final String FILENAME = "filename";
303   
304    /**
305    * The attachment file name, used for sorting.
306    */
307    public static final String FILENAME_SORT = FILENAME + SORT_SUFFIX;
308   
309    /**
310    * For storing property name.
311    */
312    public static final String PROPERTY_NAME = "propertyname";
313   
314    /**
315    * For storing property value.
316    * <p>
317    * Note: Multilingual and virtual field.
318    */
319    public static final String PROPERTY_VALUE = "propertyvalue";
320   
321    /**
322    * Underscore character, used to separate the field name from the suffix.
323    */
324    public static final String USCORE = "_";
325   
326    /**
327    * Utility class.
328    */
 
329  0 toggle private FieldUtils()
330    {
331    }
332   
333    /**
334    * Format string for multilingual fields.
335    *
336    * @param field the field name
337    * @param locale the locale of the content of the field
338    * @return the localized version of the field name
339    */
 
340  469280 toggle public static String getFieldName(String field, Locale locale)
341    {
342  469280 StringBuilder builder = new StringBuilder(field);
343   
344  469280 builder.append(USCORE);
345   
346  469280 if (locale != null) {
347  383437 if (locale.equals(Locale.ROOT)) {
348  235669 builder.append(USCORE);
349    } else {
350  147768 builder.append(locale);
351    }
352    }
353   
354  469280 return builder.toString();
355    }
356   
357    /**
358    * Get the name of a dynamic field based on its type or the given locale. If the field type is specified then it is
359    * suffixed to the field name so that its value is indexed properly (see schema.xml). Otherwise, the locale is
360    * suffixed to the field name so that the field text content is indexed based on the specified locale.
361    *
362    * @param prefix the field name prefix
363    * @param type the field type
364    * @param locale the locale of the field value in case the type is not specified
365    * @return the name that should be used for the specified field in order for its value to be indexed correctly
366    */
 
367  151384 toggle public static String getFieldName(String prefix, String type, Locale locale)
368    {
369  151384 if (type != null) {
370  119933 return prefix + FieldUtils.USCORE + type;
371    } else {
372  31451 return FieldUtils.getFieldName(prefix, locale);
373    }
374    }
375    }