1 package com.atlassian.bonnie.search.extractor;
2
3 import com.atlassian.bonnie.Searchable;
4 import com.atlassian.bonnie.search.SearchableAttachment;
5 import com.atlassian.bonnie.search.Extractor;
6 import org.apache.lucene.document.Document;
7 import org.apache.lucene.document.Field;
8
9 public class AttachmentMetadataExtractor implements Extractor
10 {
11 public void addFields(Document document, StringBuffer defaultSearchableText, Searchable searchable)
12 {
13 if (searchable instanceof SearchableAttachment)
14 {
15 SearchableAttachment attachment = (SearchableAttachment) searchable;
16
17 if (attachment.getFileName() != null && !"".equals(attachment.getFileName()))
18 {
19 Field fileNameField = new Field("filename", attachment.getFileName(), Field.Store.YES, Field.Index.TOKENIZED);
20 document.add(fileNameField);
21 document.add(new Field("title", attachment.getFileName(), Field.Store.YES, Field.Index.NO));
22 }
23
24 if (attachment.getComment() != null && !"".equals(attachment.getComment()))
25 {
26 Field commentField = new Field("comment", attachment.getComment(), Field.Store.YES, Field.Index.TOKENIZED);
27 document.add(commentField);
28 defaultSearchableText.append(attachment.getComment());
29 }
30
31 if (attachment.getNiceType() != null && !"".equals(attachment.getNiceType())) {
32 document.add(new Field("niceType", attachment.getNiceType(), Field.Store.YES, Field.Index.NO));
33 }
34
35 if (attachment.getDownloadPath() != null && !"".equals(attachment.getDownloadPath())) {
36 document.add(new Field("downloadPath", attachment.getDownloadPath(), Field.Store.YES, Field.Index.NO));
37 }
38
39 if (attachment.getNiceFileSize() != null && !"".equals(attachment.getNiceFileSize())) {
40 document.add(new Field("niceFileSize", attachment.getNiceFileSize(), Field.Store.YES, Field.Index.NO));
41 }
42 }
43 }
44 }