1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.search.lucene; |
18 |
|
|
19 |
|
import java.io.File; |
20 |
|
import java.io.IOException; |
21 |
|
import java.net.URL; |
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Collection; |
24 |
|
import java.util.HashMap; |
25 |
|
import java.util.Iterator; |
26 |
|
import java.util.Map; |
27 |
|
import java.util.Set; |
28 |
|
|
29 |
|
import org.apache.commons.collections.MultiHashMap; |
30 |
|
import org.apache.commons.collections.MultiMap; |
31 |
|
import org.apache.commons.logging.Log; |
32 |
|
import org.apache.commons.logging.LogFactory; |
33 |
|
import org.apache.jetspeed.search.BaseParsedObject; |
34 |
|
import org.apache.jetspeed.search.HandlerFactory; |
35 |
|
import org.apache.jetspeed.search.ObjectHandler; |
36 |
|
import org.apache.jetspeed.search.ParsedObject; |
37 |
|
import org.apache.jetspeed.search.SearchEngine; |
38 |
|
import org.apache.jetspeed.search.SearchResults; |
39 |
|
import org.apache.lucene.analysis.Analyzer; |
40 |
|
import org.apache.lucene.analysis.standard.StandardAnalyzer; |
41 |
|
import org.apache.lucene.document.Document; |
42 |
|
import org.apache.lucene.document.Field; |
43 |
|
import org.apache.lucene.index.IndexReader; |
44 |
|
import org.apache.lucene.index.IndexWriter; |
45 |
|
import org.apache.lucene.index.Term; |
46 |
|
import org.apache.lucene.queryParser.MultiFieldQueryParser; |
47 |
|
import org.apache.lucene.queryParser.ParseException; |
48 |
|
import org.apache.lucene.search.Hits; |
49 |
|
import org.apache.lucene.search.IndexSearcher; |
50 |
|
import org.apache.lucene.search.Query; |
51 |
|
import org.apache.lucene.search.Searcher; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
public class SearchEngineImpl implements SearchEngine |
58 |
|
{ |
59 |
0 |
protected final static Log log = LogFactory.getLog(SearchEngineImpl.class); |
60 |
0 |
private File rootIndexDir = null; |
61 |
0 |
private String analyzerClassName = null; |
62 |
0 |
private boolean optimizeAfterUpdate = true; |
63 |
|
private HandlerFactory handlerFactory; |
64 |
|
|
65 |
|
private static final int KEYWORD = 0; |
66 |
|
private static final int TEXT = 1; |
67 |
|
|
68 |
|
public SearchEngineImpl(String indexRoot, String analyzerClassName, boolean optimzeAfterUpdate, HandlerFactory handlerFactory) |
69 |
|
throws Exception |
70 |
0 |
{ |
71 |
|
|
72 |
0 |
rootIndexDir = new File(indexRoot); |
73 |
0 |
this.analyzerClassName = analyzerClassName; |
74 |
0 |
this.optimizeAfterUpdate = optimzeAfterUpdate; |
75 |
0 |
this.handlerFactory = handlerFactory; |
76 |
|
|
77 |
|
try |
78 |
|
{ |
79 |
0 |
Searcher searcher = null; |
80 |
0 |
searcher = new IndexSearcher(rootIndexDir.getPath()); |
81 |
0 |
searcher.close(); |
82 |
|
} |
83 |
0 |
catch (Exception e) |
84 |
|
{ |
85 |
0 |
if (rootIndexDir.exists()) |
86 |
|
{ |
87 |
0 |
log.error("Failed to open Portal Registry indexes in " + rootIndexDir.getPath(), e); |
88 |
|
} |
89 |
|
try |
90 |
|
{ |
91 |
0 |
rootIndexDir.delete(); |
92 |
0 |
rootIndexDir.mkdirs(); |
93 |
|
|
94 |
0 |
IndexWriter indexWriter = new IndexWriter(rootIndexDir, class="keyword">newAnalyzer(), true); |
95 |
0 |
indexWriter.close(); |
96 |
0 |
indexWriter = null; |
97 |
0 |
log.warn("Re-created Lucene Index in " + rootIndexDir.getPath()); |
98 |
|
} |
99 |
0 |
catch (Exception e1) |
100 |
|
{ |
101 |
0 |
String message = "Cannot RECREATE Portlet Registry indexes in " + rootIndexDir.getPath(); |
102 |
0 |
log.error(message, e1); |
103 |
0 |
throw new Exception(message); |
104 |
0 |
} |
105 |
0 |
} |
106 |
0 |
} |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
public boolean add(Object o) |
112 |
|
{ |
113 |
0 |
Collection c = new ArrayList(1); |
114 |
0 |
c.add(o); |
115 |
|
|
116 |
0 |
return add(c); |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
public synchronized boolean add(Collection objects) |
123 |
|
{ |
124 |
0 |
boolean result = false; |
125 |
|
|
126 |
|
IndexWriter indexWriter; |
127 |
|
try |
128 |
|
{ |
129 |
0 |
indexWriter = new IndexWriter(rootIndexDir, class="keyword">newAnalyzer(), false); |
130 |
|
} |
131 |
0 |
catch (IOException e) |
132 |
|
{ |
133 |
|
|
134 |
0 |
return result; |
135 |
0 |
} |
136 |
|
|
137 |
0 |
Iterator it = objects.iterator(); |
138 |
0 |
while (it.hasNext()) |
139 |
|
{ |
140 |
0 |
Object o = it.next(); |
141 |
|
|
142 |
0 |
ObjectHandler handler = null; |
143 |
|
try |
144 |
|
{ |
145 |
0 |
handler = handlerFactory.getHandler(o); |
146 |
|
} |
147 |
0 |
catch (Exception e) |
148 |
|
{ |
149 |
|
|
150 |
0 |
continue; |
151 |
0 |
} |
152 |
|
|
153 |
|
|
154 |
0 |
ParsedObject parsedObject = handler.parseObject(o); |
155 |
|
|
156 |
|
|
157 |
0 |
Document doc = new Document(); |
158 |
|
|
159 |
|
|
160 |
0 |
if (parsedObject.getKey() != null) |
161 |
|
{ |
162 |
0 |
doc.add(new Field(ParsedObject.FIELDNAME_KEY, parsedObject.getKey(), Field.Store.YES, Field.Index.UN_TOKENIZED)); |
163 |
|
} |
164 |
0 |
if (parsedObject.getType() != null) |
165 |
|
{ |
166 |
0 |
doc.add(new Field(ParsedObject.FIELDNAME_TYPE, parsedObject.getType(), Field.Store.YES, Field.Index.TOKENIZED)); |
167 |
|
} |
168 |
0 |
if (parsedObject.getTitle() != null) |
169 |
|
{ |
170 |
0 |
doc.add(new Field(ParsedObject.FIELDNAME_TITLE, parsedObject.getTitle(), Field.Store.YES, Field.Index.TOKENIZED)); |
171 |
|
} |
172 |
0 |
if (parsedObject.getDescription() != null) |
173 |
|
{ |
174 |
0 |
doc.add(new Field(ParsedObject.FIELDNAME_DESCRIPTION, parsedObject.getDescription(), Field.Store.YES, Field.Index.TOKENIZED)); |
175 |
|
} |
176 |
0 |
if (parsedObject.getContent() != null) |
177 |
|
{ |
178 |
0 |
doc.add(new Field(ParsedObject.FIELDNAME_CONTENT, parsedObject.getContent(), Field.Store.YES, Field.Index.TOKENIZED)); |
179 |
|
} |
180 |
0 |
if (parsedObject.getLanguage() != null) |
181 |
|
{ |
182 |
0 |
doc.add(new Field(ParsedObject.FIELDNAME_LANGUAGE, parsedObject.getLanguage(), Field.Store.YES, Field.Index.TOKENIZED)); |
183 |
|
} |
184 |
0 |
if (parsedObject.getURL() != null) |
185 |
|
{ |
186 |
0 |
doc.add(new Field(ParsedObject.FIELDNAME_URL, parsedObject.getURL().toString(), Field.Store.YES, Field.Index.TOKENIZED)); |
187 |
|
} |
188 |
0 |
if(parsedObject.getClassName() != null) |
189 |
|
{ |
190 |
0 |
doc.add(new Field(ParsedObject.FIELDNAME_CLASSNAME, parsedObject.getClassName(), Field.Store.YES, Field.Index.TOKENIZED)); |
191 |
|
} |
192 |
|
|
193 |
0 |
String[] keywordArray = parsedObject.getKeywords(); |
194 |
0 |
if(keywordArray != null) |
195 |
|
{ |
196 |
0 |
for(int i=0; i<keywordArray.length; ++i) |
197 |
|
{ |
198 |
0 |
String keyword = keywordArray[i]; |
199 |
0 |
doc.add(new Field(ParsedObject.FIELDNAME_KEYWORDS, keyword, Field.Store.YES, Field.Index.UN_TOKENIZED)); |
200 |
|
} |
201 |
|
} |
202 |
|
|
203 |
0 |
Map keywords = parsedObject.getKeywordsMap(); |
204 |
0 |
addFieldsToDocument(doc, keywords, KEYWORD); |
205 |
|
|
206 |
0 |
Map fields = parsedObject.getFields(); |
207 |
0 |
addFieldsToDocument(doc, fields, TEXT); |
208 |
|
|
209 |
|
|
210 |
|
try |
211 |
|
{ |
212 |
0 |
indexWriter.addDocument(doc); |
213 |
|
} |
214 |
0 |
catch (IOException e) |
215 |
|
{ |
216 |
|
|
217 |
0 |
} |
218 |
|
|
219 |
|
|
220 |
0 |
result = true; |
221 |
0 |
} |
222 |
|
|
223 |
|
try |
224 |
|
{ |
225 |
0 |
if(optimizeAfterUpdate) |
226 |
|
{ |
227 |
0 |
indexWriter.optimize(); |
228 |
|
} |
229 |
|
} |
230 |
0 |
catch (IOException e) |
231 |
|
{ |
232 |
|
|
233 |
|
} |
234 |
|
finally |
235 |
|
{ |
236 |
0 |
try |
237 |
|
{ |
238 |
0 |
indexWriter.close(); |
239 |
|
} |
240 |
0 |
catch (IOException e) |
241 |
|
{ |
242 |
|
|
243 |
0 |
} |
244 |
0 |
} |
245 |
|
|
246 |
0 |
return result; |
247 |
|
} |
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
public boolean remove(Object o) |
253 |
|
{ |
254 |
0 |
Collection c = new ArrayList(1); |
255 |
0 |
c.add(o); |
256 |
|
|
257 |
0 |
return remove(c); |
258 |
|
} |
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
public synchronized boolean remove(Collection objects) |
264 |
|
{ |
265 |
0 |
boolean result = false; |
266 |
|
|
267 |
|
try |
268 |
|
{ |
269 |
0 |
IndexReader indexReader = IndexReader.open(this.rootIndexDir); |
270 |
|
|
271 |
0 |
Iterator it = objects.iterator(); |
272 |
0 |
while (it.hasNext()) |
273 |
|
{ |
274 |
0 |
Object o = it.next(); |
275 |
|
|
276 |
0 |
ObjectHandler handler = handlerFactory.getHandler(o); |
277 |
|
|
278 |
|
|
279 |
0 |
ParsedObject parsedObject = handler.parseObject(o); |
280 |
|
|
281 |
|
|
282 |
0 |
Term term = null; |
283 |
|
|
284 |
0 |
if (parsedObject.getKey() != null) |
285 |
|
{ |
286 |
0 |
term = new Term(ParsedObject.FIELDNAME_KEY, parsedObject.getKey()); |
287 |
|
|
288 |
0 |
int rc = indexReader.deleteDocuments(term); |
289 |
|
|
290 |
|
|
291 |
0 |
result = rc > 0; |
292 |
|
} |
293 |
0 |
} |
294 |
|
|
295 |
0 |
indexReader.close(); |
296 |
|
|
297 |
0 |
if(optimizeAfterUpdate) |
298 |
|
{ |
299 |
0 |
optimize(); |
300 |
|
} |
301 |
|
|
302 |
|
} |
303 |
0 |
catch (Exception e) |
304 |
|
{ |
305 |
|
|
306 |
0 |
result = false; |
307 |
0 |
} |
308 |
|
|
309 |
0 |
return result; |
310 |
|
} |
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
public boolean update(Object o) |
316 |
|
{ |
317 |
0 |
Collection c = new ArrayList(1); |
318 |
0 |
c.add(o); |
319 |
|
|
320 |
0 |
return update(c); |
321 |
|
} |
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
public synchronized boolean update(Collection objects) |
327 |
|
{ |
328 |
0 |
boolean result = false; |
329 |
|
|
330 |
|
try |
331 |
|
{ |
332 |
|
|
333 |
0 |
remove(objects); |
334 |
0 |
result = true; |
335 |
|
} |
336 |
0 |
catch (Throwable e) |
337 |
|
{ |
338 |
|
|
339 |
0 |
} |
340 |
|
|
341 |
|
try |
342 |
|
{ |
343 |
|
|
344 |
0 |
if(result) |
345 |
|
{ |
346 |
0 |
add(objects); |
347 |
0 |
result = true; |
348 |
|
} |
349 |
|
} |
350 |
0 |
catch (Throwable e) |
351 |
|
{ |
352 |
|
|
353 |
0 |
} |
354 |
|
|
355 |
0 |
return result; |
356 |
|
} |
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
public synchronized boolean optimize() |
362 |
|
{ |
363 |
0 |
boolean result = false; |
364 |
|
|
365 |
|
try |
366 |
|
{ |
367 |
0 |
IndexWriter indexWriter = new IndexWriter(rootIndexDir, class="keyword">newAnalyzer(), false); |
368 |
0 |
indexWriter.optimize(); |
369 |
0 |
indexWriter.close(); |
370 |
0 |
result = true; |
371 |
|
} |
372 |
0 |
catch (IOException e) |
373 |
|
{ |
374 |
|
|
375 |
0 |
} |
376 |
0 |
return result; |
377 |
|
} |
378 |
|
|
379 |
|
|
380 |
|
|
381 |
|
|
382 |
|
public SearchResults search(String queryString) |
383 |
|
{ |
384 |
0 |
Searcher searcher = null; |
385 |
0 |
Hits hits = null; |
386 |
|
|
387 |
|
try |
388 |
|
{ |
389 |
0 |
searcher = new IndexSearcher(rootIndexDir.getPath()); |
390 |
|
} |
391 |
0 |
catch (IOException e) |
392 |
|
{ |
393 |
|
|
394 |
0 |
return null; |
395 |
0 |
} |
396 |
|
|
397 |
0 |
Analyzer analyzer = newAnalyzer(); |
398 |
|
|
399 |
0 |
String[] searchFields = {ParsedObject.FIELDNAME_CONTENT, ParsedObject.FIELDNAME_DESCRIPTION, ParsedObject.FIELDNAME_FIELDS, |
400 |
|
ParsedObject.FIELDNAME_KEY, ParsedObject.FIELDNAME_KEYWORDS, ParsedObject.FIELDNAME_LANGUAGE, |
401 |
|
ParsedObject.FIELDNAME_SCORE, ParsedObject.FIELDNAME_TITLE, ParsedObject.FIELDNAME_TYPE, |
402 |
|
ParsedObject.FIELDNAME_URL, ParsedObject.FIELDNAME_CLASSNAME}; |
403 |
|
|
404 |
0 |
Query query= null; |
405 |
|
try |
406 |
|
{ |
407 |
0 |
String s[] = new String[searchFields.length]; |
408 |
0 |
for(int i=0;i<s.length;i++) |
409 |
0 |
s[i] = queryString; |
410 |
0 |
query = MultiFieldQueryParser.parse(s, searchFields, analyzer); |
411 |
|
|
412 |
|
} |
413 |
0 |
catch (ParseException e) |
414 |
|
{ |
415 |
|
|
416 |
0 |
return null; |
417 |
0 |
} |
418 |
|
|
419 |
|
try |
420 |
|
{ |
421 |
0 |
hits = searcher.search(query); |
422 |
|
} |
423 |
0 |
catch (IOException e) |
424 |
|
{ |
425 |
|
|
426 |
0 |
return null; |
427 |
0 |
} |
428 |
|
|
429 |
0 |
int hitNum = hits.length(); |
430 |
0 |
ArrayList resultList = new ArrayList(hitNum); |
431 |
0 |
for(int i=0; i<hitNum; i++) |
432 |
|
{ |
433 |
0 |
ParsedObject result = new BaseParsedObject(); |
434 |
|
try |
435 |
|
{ |
436 |
0 |
Document doc = hits.doc(i); |
437 |
|
|
438 |
0 |
addFieldsToParsedObject(doc, result); |
439 |
|
|
440 |
0 |
result.setScore(hits.score(i)); |
441 |
0 |
Field type = doc.getField(ParsedObject.FIELDNAME_TYPE); |
442 |
0 |
if(type != null) |
443 |
|
{ |
444 |
0 |
result.setType(type.stringValue()); |
445 |
|
} |
446 |
|
|
447 |
0 |
Field key = doc.getField(ParsedObject.FIELDNAME_KEY); |
448 |
0 |
if(key != null) |
449 |
|
{ |
450 |
0 |
result.setKey(key.stringValue()); |
451 |
|
} |
452 |
|
|
453 |
0 |
Field description = doc.getField(ParsedObject.FIELDNAME_DESCRIPTION); |
454 |
0 |
if(description != null) |
455 |
|
{ |
456 |
0 |
result.setDescription(description.stringValue()); |
457 |
|
} |
458 |
|
|
459 |
0 |
Field title = doc.getField(ParsedObject.FIELDNAME_TITLE); |
460 |
0 |
if(title != null) |
461 |
|
{ |
462 |
0 |
result.setTitle(title.stringValue()); |
463 |
|
} |
464 |
|
|
465 |
0 |
Field content = doc.getField(ParsedObject.FIELDNAME_CONTENT); |
466 |
0 |
if(content != null) |
467 |
|
{ |
468 |
0 |
result.setContent(content.stringValue()); |
469 |
|
} |
470 |
|
|
471 |
0 |
Field language = doc.getField(ParsedObject.FIELDNAME_LANGUAGE); |
472 |
0 |
if (language != null) |
473 |
|
{ |
474 |
0 |
result.setLanguage(language.stringValue()); |
475 |
|
} |
476 |
|
|
477 |
0 |
Field classname = doc.getField(ParsedObject.FIELDNAME_CLASSNAME); |
478 |
0 |
if (classname != null) |
479 |
|
{ |
480 |
0 |
result.setClassName(classname.stringValue()); |
481 |
|
} |
482 |
|
|
483 |
0 |
Field url = doc.getField(ParsedObject.FIELDNAME_URL); |
484 |
0 |
if (url != null) |
485 |
|
{ |
486 |
0 |
result.setURL(new URL(url.stringValue())); |
487 |
|
} |
488 |
|
|
489 |
0 |
Field[] keywords = doc.getFields(ParsedObject.FIELDNAME_KEYWORDS); |
490 |
0 |
if(keywords != null) |
491 |
|
{ |
492 |
0 |
String[] keywordArray = new String[keywords.length]; |
493 |
|
|
494 |
0 |
for(int j=0; j<keywords.length; j++) |
495 |
|
{ |
496 |
0 |
Field keyword = keywords[j]; |
497 |
0 |
keywordArray[j] = keyword.stringValue(); |
498 |
|
} |
499 |
|
|
500 |
0 |
result.setKeywords(keywordArray); |
501 |
|
} |
502 |
|
|
503 |
0 |
resultList.add(i, result); |
504 |
|
} |
505 |
0 |
catch(IOException e) |
506 |
|
{ |
507 |
|
|
508 |
0 |
} |
509 |
|
} |
510 |
|
|
511 |
0 |
if (searcher != null) |
512 |
|
{ |
513 |
|
try |
514 |
|
{ |
515 |
0 |
searcher.close(); |
516 |
|
} |
517 |
0 |
catch (IOException ioe) |
518 |
|
{ |
519 |
|
|
520 |
0 |
} |
521 |
|
} |
522 |
|
|
523 |
0 |
SearchResults results = new SearchResultsImpl(resultList); |
524 |
0 |
return results; |
525 |
|
} |
526 |
|
|
527 |
|
private Analyzer newAnalyzer() { |
528 |
0 |
Analyzer rval = null; |
529 |
|
|
530 |
0 |
if(analyzerClassName != null) |
531 |
|
{ |
532 |
|
try { |
533 |
0 |
Class analyzerClass = Class.forName(analyzerClassName); |
534 |
0 |
rval = (Analyzer) analyzerClass.newInstance(); |
535 |
0 |
} catch(InstantiationException e) { |
536 |
|
|
537 |
0 |
} catch(ClassNotFoundException e) { |
538 |
|
|
539 |
0 |
} catch(IllegalAccessException e) { |
540 |
|
|
541 |
0 |
} |
542 |
|
} |
543 |
|
|
544 |
0 |
if(rval == null) { |
545 |
0 |
rval = new StandardAnalyzer(); |
546 |
|
} |
547 |
|
|
548 |
0 |
return rval; |
549 |
|
} |
550 |
|
|
551 |
|
private void addFieldsToDocument(Document doc, Map fields, int type) |
552 |
|
{ |
553 |
0 |
if(fields != null) |
554 |
|
{ |
555 |
0 |
Iterator keyIter = fields.keySet().iterator(); |
556 |
0 |
while(keyIter.hasNext()) |
557 |
|
{ |
558 |
0 |
Object key = keyIter.next(); |
559 |
0 |
if(key != null) |
560 |
|
{ |
561 |
0 |
Object values = fields.get(key); |
562 |
0 |
if(values != null) |
563 |
|
{ |
564 |
0 |
if(values instanceof Collection) |
565 |
|
{ |
566 |
0 |
Iterator valueIter = ((Collection)values).iterator(); |
567 |
0 |
while(valueIter.hasNext()) |
568 |
|
{ |
569 |
0 |
Object value = valueIter.next(); |
570 |
0 |
if(value != null) |
571 |
|
{ |
572 |
0 |
if(type == TEXT) |
573 |
|
{ |
574 |
0 |
doc.add(new Field(key.toString(), value.toString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); |
575 |
|
} |
576 |
|
else |
577 |
|
{ |
578 |
0 |
doc.add(new Field(key.toString(), value.toString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); |
579 |
|
} |
580 |
|
} |
581 |
0 |
} |
582 |
0 |
} |
583 |
|
else |
584 |
|
{ |
585 |
0 |
if(type == TEXT) |
586 |
|
{ |
587 |
0 |
doc.add(new Field(key.toString(), values.toString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); |
588 |
|
} |
589 |
|
else |
590 |
|
{ |
591 |
0 |
doc.add(new Field(key.toString(), values.toString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); |
592 |
|
} |
593 |
|
} |
594 |
|
} |
595 |
|
} |
596 |
0 |
} |
597 |
|
} |
598 |
0 |
} |
599 |
|
|
600 |
|
private void addFieldsToParsedObject(Document doc, ParsedObject o) |
601 |
|
{ |
602 |
|
try |
603 |
|
{ |
604 |
0 |
MultiMap multiKeywords = new MultiHashMap(); |
605 |
0 |
MultiMap multiFields = new MultiHashMap(); |
606 |
0 |
HashMap fieldMap = new HashMap(); |
607 |
|
|
608 |
0 |
Field classNameField = doc.getField(ParsedObject.FIELDNAME_CLASSNAME); |
609 |
0 |
if(classNameField != null) |
610 |
|
{ |
611 |
0 |
String className = classNameField.stringValue(); |
612 |
0 |
o.setClassName(className); |
613 |
0 |
ObjectHandler handler = handlerFactory.getHandler(className); |
614 |
|
|
615 |
0 |
Set fields = handler.getFields(); |
616 |
0 |
addFieldsToMap(doc, fields, multiFields); |
617 |
0 |
addFieldsToMap(doc, fields, fieldMap); |
618 |
|
|
619 |
0 |
Set keywords = handler.getKeywords(); |
620 |
0 |
addFieldsToMap(doc, keywords, multiKeywords); |
621 |
|
} |
622 |
|
|
623 |
0 |
o.setKeywordsMap(multiKeywords); |
624 |
0 |
o.setFields(multiFields); |
625 |
0 |
o.setFields(fieldMap); |
626 |
|
} |
627 |
0 |
catch(Exception e) |
628 |
|
{ |
629 |
|
|
630 |
0 |
} |
631 |
0 |
} |
632 |
|
|
633 |
|
private void addFieldsToMap(Document doc, Set fieldNames, Map fields) |
634 |
|
{ |
635 |
0 |
Iterator fieldIter = fieldNames.iterator(); |
636 |
0 |
while(fieldIter.hasNext()) |
637 |
|
{ |
638 |
0 |
String fieldName = (String)fieldIter.next(); |
639 |
0 |
Field[] docFields = doc.getFields(fieldName); |
640 |
0 |
if(docFields != null) |
641 |
|
{ |
642 |
0 |
for(int i=0; i<docFields.length; i++) |
643 |
|
{ |
644 |
0 |
Field field = docFields[i]; |
645 |
0 |
if(field != null) |
646 |
|
{ |
647 |
0 |
String value = field.stringValue(); |
648 |
0 |
fields.put(fieldName, value); |
649 |
|
} |
650 |
|
} |
651 |
|
} |
652 |
0 |
} |
653 |
0 |
} |
654 |
|
} |