1 31 32 package org.opencms.search; 33 34 import org.opencms.monitor.CmsMemoryMonitor; 35 import org.opencms.monitor.I_CmsMemoryMonitorable; 36 import org.opencms.search.documents.I_CmsDocumentFactory; 37 38 import java.text.ParseException ; 39 import java.util.Date ; 40 41 import org.apache.lucene.document.DateTools; 42 import org.apache.lucene.document.Document; 43 import org.apache.lucene.document.Field; 44 45 54 public class CmsSearchResult implements I_CmsMemoryMonitorable, Comparable { 55 56 57 protected Date m_dateCreated; 58 59 60 protected Date m_dateLastModified; 61 62 63 protected String m_description; 64 65 66 protected String m_excerpt; 67 68 69 protected String m_keyWords; 70 71 72 protected String m_path; 73 74 75 protected int m_score; 76 77 78 protected String m_title; 79 80 87 protected CmsSearchResult(int score, Document luceneDocument, String excerpt) { 88 89 Field f; 90 91 m_score = score; 92 m_excerpt = excerpt; 93 94 f = luceneDocument.getField(I_CmsDocumentFactory.DOC_DESCRIPTION); 95 if (f != null) { 96 m_description = f.stringValue(); 97 } else { 98 m_description = null; 99 } 100 101 f = luceneDocument.getField(I_CmsDocumentFactory.DOC_KEYWORDS); 102 if (f != null) { 103 m_keyWords = f.stringValue(); 104 } else { 105 m_keyWords = null; 106 } 107 108 f = luceneDocument.getField(I_CmsDocumentFactory.DOC_TITLE_KEY); 109 if (f != null) { 110 m_title = f.stringValue(); 111 } else { 112 m_title = null; 113 } 114 115 f = luceneDocument.getField(I_CmsDocumentFactory.DOC_PATH); 116 if (f != null) { 117 m_path = f.stringValue(); 118 } else { 119 m_path = null; 120 } 121 122 f = luceneDocument.getField(I_CmsDocumentFactory.DOC_DATE_CREATED); 123 if (f != null) { 124 try { 125 m_dateCreated = DateTools.stringToDate(f.stringValue()); 126 } catch (ParseException exc) { 127 m_dateCreated = null; 128 } 129 } else { 130 m_dateCreated = null; 131 } 132 133 f = luceneDocument.getField(I_CmsDocumentFactory.DOC_DATE_LASTMODIFIED); 134 if (f != null) { 135 try { 136 m_dateLastModified = DateTools.stringToDate(f.stringValue()); 137 } catch (ParseException exc) { 138 m_dateLastModified = null; 139 } 140 } else { 141 m_dateLastModified = null; 142 } 143 } 144 145 148 public int compareTo(Object obj) { 149 150 if (obj == this) { 151 return 0; 152 } 153 if (obj instanceof CmsSearchResult) { 154 return ((CmsSearchResult)obj).m_score - m_score; 155 } 156 return 0; 157 } 158 159 164 public Date getDateCreated() { 165 166 return m_dateCreated; 167 } 168 169 174 public Date getDateLastModified() { 175 176 return m_dateLastModified; 177 } 178 179 184 public String getDescription() { 185 186 return m_description; 187 } 188 189 194 public String getExcerpt() { 195 196 return m_excerpt; 197 } 198 199 204 public String getKeywords() { 205 206 return m_keyWords; 207 } 208 209 212 public int getMemorySize() { 213 214 int result = 8; 215 216 if (m_dateCreated != null) { 217 result += CmsMemoryMonitor.getMemorySize(m_dateCreated); 218 } 219 220 if (m_dateLastModified != null) { 221 result += CmsMemoryMonitor.getMemorySize(m_dateLastModified); 222 } 223 224 if (m_path != null) { 225 result += CmsMemoryMonitor.getMemorySize(m_path); 226 } 227 228 if (m_title != null) { 229 result += CmsMemoryMonitor.getMemorySize(m_title); 230 } 231 232 if (m_description != null) { 233 result += CmsMemoryMonitor.getMemorySize(m_description); 234 } 235 236 if (m_keyWords != null) { 237 result += CmsMemoryMonitor.getMemorySize(m_keyWords); 238 } 239 240 if (m_excerpt != null) { 241 result += CmsMemoryMonitor.getMemorySize(m_excerpt); 242 } 243 244 return result; 245 } 246 247 252 public String getPath() { 253 254 return m_path; 255 } 256 257 262 public int getScore() { 263 264 return m_score; 265 } 266 267 272 public String getTitle() { 273 274 return m_title; 275 } 276 277 }
| Popular Tags
|