1
22
23 package com.liferay.portal.lucene;
24
25 import com.liferay.portal.kernel.util.InstancePool;
26 import com.liferay.portal.kernel.util.StringMaker;
27 import com.liferay.portal.util.PropsValues;
28
29 import java.io.File;
30 import java.io.IOException;
31 import java.io.InputStream;
32
33 import java.util.Date;
34
35 import org.apache.lucene.document.DateTools;
36 import org.apache.lucene.document.Field;
37
38
44 public class LuceneFields {
45
46 public static final String UID = "uid";
47
48 public static final String COMPANY_ID = "companyId";
49
50 public static final String PORTLET_ID = "portletId";
51
52 public static final String GROUP_ID = "groupId";
53
54 public static final String USER_ID = "userId";
55
56 public static final String USER_NAME = "userName";
57
58 public static final String TYPE = "type";
59
60 public static final String TITLE = "title";
61
62 public static final String NAME = "name";
63
64 public static final String DESCRIPTION = "description";
65
66 public static final String CONTENT = "content";
67
68 public static final String PROPERTIES = "properties";
69
70 public static final String MODIFIED = "modified";
71
72 public static final String VERSION_LABEL = "versionLabel";
73
74 public static final String TAG_ENTRY = "tag_entry";
75
76 public static String getUID(String portletId, long field1) {
77 return getUID(portletId, String.valueOf(field1));
78 }
79
80 public static String getUID(String portletId, Long field1) {
81 return getUID(portletId, field1.longValue());
82 }
83
84 public static String getUID(String portletId, String field1) {
85 return getUID(portletId, field1, null);
86 }
87
88 public static String getUID(
89 String portletId, long field1, String field2) {
90
91 return getUID(portletId, String.valueOf(field1), field2);
92 }
93
94 public static String getUID(
95 String portletId, Long field1, String field2) {
96
97 return getUID(portletId, field1.longValue(), field2);
98 }
99
100 public static String getUID(
101 String portletId, String field1, String field2) {
102
103 return getUID(portletId, field1, field2, null);
104 }
105
106 public static String getUID(
107 String portletId, String field1, String field2, String field3) {
108
109 String uid = portletId + _UID_PORTLET + field1;
110
111 if (field2 != null) {
112 uid += _UID_FIELD + field2;
113 }
114
115 if (field3 != null) {
116 uid += _UID_FIELD + field3;
117 }
118
119 return uid;
120 }
121
122 public static Field getDate(String field) {
123 return getDate(field, new Date());
124 }
125
126 public static Field getDate(String field, Date date) {
127 if (date == null) {
128 return getDate(field);
129 }
130 else {
131 return new Field(
132 field,
133 DateTools.dateToString(date, DateTools.Resolution.SECOND),
134 Field.Store.YES, Field.Index.UN_TOKENIZED);
135 }
136 }
137
138 public static Field getFile(String field, InputStream is, String fileExt)
139 throws IOException {
140
141 LuceneFileExtractor fileExtractor =
142 (LuceneFileExtractor)InstancePool.get(
143 PropsValues.LUCENE_FILE_EXTRACTOR);
144
145 return fileExtractor.getFile(field, is, fileExt);
146 }
147
148 public static Field getFile(String field, byte[] byteArray, String fileExt)
149 throws IOException {
150
151 LuceneFileExtractor fileExtractor =
152 (LuceneFileExtractor)InstancePool.get(
153 PropsValues.LUCENE_FILE_EXTRACTOR);
154
155 return fileExtractor.getFile(field, byteArray, fileExt);
156 }
157
158 public static Field getFile(String field, File file, String fileExt)
159 throws IOException {
160
161 LuceneFileExtractor fileExtractor =
162 (LuceneFileExtractor)InstancePool.get(
163 PropsValues.LUCENE_FILE_EXTRACTOR);
164
165 return fileExtractor.getFile(field, file, fileExt);
166 }
167
168 public static Field getKeyword(String field, double keyword) {
169 return getKeyword(field, String.valueOf(keyword));
170 }
171
172 public static Field getKeyword(String field, long keyword) {
173 return getKeyword(field, String.valueOf(keyword));
174 }
175
176 public static Field getKeyword(String field, Long keyword) {
177 return getKeyword(field, keyword.longValue());
178 }
179
180 public static Field getKeyword(String field, String keyword) {
181
183 Field fieldObj = new Field(
184 field, keyword, Field.Store.YES, Field.Index.UN_TOKENIZED);
185
186
188 return fieldObj;
189 }
190
191 public static Field getText(String field, String text) {
192 return new Field(field, text, Field.Store.YES, Field.Index.TOKENIZED);
193 }
194
195 public static Field getText(String field, StringMaker sm) {
196 return getText(field, sm.toString());
197 }
198
199 private static final String _UID_PORTLET = "_PORTLET_";
200
201 private static final String _UID_FIELD = "_FIELD_";
202
203 }