View Javadoc

1   package com.atlassian.bonnie.search.extractor;
2   
3   import org.apache.lucene.document.Document;
4   import org.apache.lucene.document.Field;
5   
6   import com.atlassian.bonnie.Searchable;
7   import com.atlassian.bonnie.search.Extractor;
8   import com.atlassian.bonnie.search.SearchableAttachment;
9   
10  public class AttachmentMetadataExtractor implements Extractor
11  {
12  	/**
13  	 * This may change, don't consider this part of a public API
14  	 */
15  	public static class FieldName
16  	{
17  		public static final String NICE_TYPE = "niceType";
18  		public static final String DOWNLOAD_PATH = "downloadPath";
19  		public static final String NICE_FILE_SIZE = "niceFileSize";
20  	}
21  
22  	public void addFields(Document document, StringBuffer defaultSearchableText, Searchable searchable)
23      {
24          if (searchable instanceof SearchableAttachment)
25          {
26              SearchableAttachment attachment = (SearchableAttachment) searchable;
27  
28              if (attachment.getFileName() != null && !"".equals(attachment.getFileName()))
29              {
30                  Field fileNameField = new Field("filename", attachment.getFileName(), Field.Store.YES, Field.Index.TOKENIZED);
31                  document.add(fileNameField);
32                  document.add(new Field("title", attachment.getFileName(), Field.Store.YES, Field.Index.NO));
33              }
34  
35              if (attachment.getComment() != null && !"".equals(attachment.getComment()))
36              {
37                  Field commentField = new Field("comment", attachment.getComment(), Field.Store.YES, Field.Index.TOKENIZED);
38                  document.add(commentField);
39                  defaultSearchableText.append(" ").append(attachment.getComment());
40              }
41  
42              if (attachment.getNiceType() != null && !"".equals(attachment.getNiceType())) {
43                  document.add(new Field(FieldName.NICE_TYPE, attachment.getNiceType(), Field.Store.YES, Field.Index.UN_TOKENIZED));
44              }
45  
46              if (attachment.getDownloadPath() != null && !"".equals(attachment.getDownloadPath())) {
47                  document.add(new Field(FieldName.DOWNLOAD_PATH, attachment.getDownloadPath(), Field.Store.YES, Field.Index.NO));
48              }
49  
50              if (attachment.getNiceFileSize() != null && !"".equals(attachment.getNiceFileSize())) {
51                  document.add(new Field(FieldName.NICE_FILE_SIZE, attachment.getNiceFileSize(), Field.Store.YES, Field.Index.NO));
52              }
53          }
54      }
55  }