01: package org.nemesis.forum.search;
02:
03: import org.apache.commons.logging.Log;
04: import org.apache.commons.logging.LogFactory;
05: import org.apache.lucene.document.DateField;
06: import org.apache.lucene.document.Document;
07: import org.apache.lucene.document.Field;
08: import org.nemesis.forum.Message;
09:
10: /**
11: * @author dlaurent
12: *
13: * ForumMessage to Lucene Document
14: */
15: public class MessageDocument {
16: static protected Log log = LogFactory.getLog(MessageDocument.class);
17:
18: public static Document getDocument(Message m) {
19:
20: try {
21: // créé un nouveau document
22: Document doc = new Document();
23: doc.add(Field.Keyword("messageID", Integer.toString(m
24: .getID())));
25: doc.add(new Field("userID", Integer.toString(m.getUser()
26: .getID()), false, true, false));
27: doc.add(new Field("threadID", Integer.toString(m
28: .getForumThread().getID()), false, true, false));
29: doc.add(new Field("forumID", Integer.toString(m
30: .getForumThread().getForum().getID()), false, true,
31: false));
32: doc.add(Field.UnStored("subject", m.getSubject()));
33: doc.add(Field.UnStored("body", m.getBody()));
34: doc.add(new Field("creationDate", DateField.dateToString(m
35: .getCreationDate()), false, true, false));
36:
37: return doc;
38:
39: } catch (Throwable e) {
40: log.error("lucene document cannot be created", e);
41: return null;
42: }
43: }
44: }
|