1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.eos.lucene;
17
18 import static org.apache.lucene.document.Field.Index.TOKENIZED;
19 import static org.apache.lucene.document.Field.Index.UN_TOKENIZED;
20 import static org.apache.lucene.document.Field.Store.YES;
21 import static org.apache.lucene.document.Field.Store.NO;
22 import net.sf.eos.EosException;
23 import net.sf.eos.document.EosDocument;
24
25 import org.apache.lucene.document.Document;
26 import org.apache.lucene.document.Field;
27
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Map.Entry;
31
32
33
34
35
36
37
38
39
40
41
42
43
44 public class DefaultLuceneDocumentCreator extends LuceneDocumentCreator
45 implements CommonDocument {
46
47
48 @Override
49 public Document createLuceneForEosDocument(final EosDocument doc)
50 throws EosException {
51
52 final Document lDoc = new Document();
53 final String text = doc.getText().toString();
54 final Field content = new Field(FieldName.CONTENT.name(),
55 text,
56 NO,
57 TOKENIZED);
58 lDoc.add(content);
59
60 final Map<String, List<String>> meta = doc.getMeta();
61 if (meta != null) {
62 for (final Entry<String, List<String>> entry : meta.entrySet()) {
63 final List<String> values = entry.getValue();
64 if (values != null && values.size() != 0) {
65 final String key = entry.getKey();
66 for (final String value : values) {
67 Field f = null;
68 if (EosDocument.YEAR_META_KEY.equals(key)) {
69 f = new Field(FieldName.YEAR.name(),
70 value,
71 YES,
72 UN_TOKENIZED);
73 } else if (EosDocument.ID_META_KEY.equals(key)) {
74 f = new Field(FieldName.ID.name(),
75 value,
76 YES,
77 UN_TOKENIZED);
78 } else if (EosDocument.CREATOR_META_KEY.equals(key)) {
79 f = new Field(FieldName.CREATOR.name(),
80 value,
81 YES,
82 TOKENIZED);
83 }
84 if (f != null) {
85 lDoc.add(f);
86 }
87 }
88 }
89 }
90 }
91
92 return lDoc;
93 }
94 }