KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > contineo > searchengine > search > Result


1 /*
2  * Result.java
3  *
4  * Created on 6. November 2003, 16:21
5  */

6 package org.contineo.searchengine.search;
7
8 import java.io.Serializable JavaDoc;
9 import java.util.Date JavaDoc;
10 /**
11  * @author Michael Scholz
12  */

13 public class Result implements Serializable JavaDoc {
14
15     private static final long serialVersionUID = 1L;
16     private Integer JavaDoc docid = new Integer JavaDoc(0);
17     /**
18      * @uml.property name="name"
19      */

20     private String JavaDoc name = "";
21     /**
22      * @uml.property name="summary"
23      */

24     private String JavaDoc summary = "";
25     /**
26      * @uml.property name="path"
27      */

28     private String JavaDoc path = "";
29     /**
30      * @uml.property name="menuid"
31      */

32     private String JavaDoc menuid = "";
33     /**
34      * @uml.property name="type"
35      */

36     private String JavaDoc type = "";
37     /**
38      * @uml.property name="icon"
39      */

40     private String JavaDoc icon = "";
41     /**
42      * @uml.property name="size"
43      */

44     private String JavaDoc size = "";
45     private Date JavaDoc date = new Date JavaDoc();
46     private Integer JavaDoc length = new Integer JavaDoc(0);
47     /**
48      * @uml.property name="green"
49      */

50     private Integer JavaDoc green = new Integer JavaDoc(0);
51     /**
52      * @uml.property name="red"
53      */

54     private Integer JavaDoc red = new Integer JavaDoc(0);
55     
56     /** Creates a new instance of Result */
57     public Result() {
58     }
59
60     /**
61      * @return Returns the docid.
62      * @uml.property name="docid"
63      */

64     public Integer JavaDoc getDocid() {
65         return docid;
66     }
67     
68     /**
69      * @param docid The docid to set.
70      * @uml.property name="docid"
71      */

72     public void setDocid(Integer JavaDoc docid) {
73         this.docid = docid;
74     }
75     
76     /**
77      *
78      * @uml.property name="name"
79      */

80     public String JavaDoc getName() {
81         return name;
82     }
83
84     /**
85      *
86      * @uml.property name="summary"
87      */

88     public String JavaDoc getSummary() {
89         return summary;
90     }
91
92     /**
93      *
94      * @uml.property name="path"
95      */

96     public String JavaDoc getPath() {
97         return path;
98     }
99
100     /**
101      *
102      * @uml.property name="menuid"
103      */

104     public String JavaDoc getMenuid() {
105         return menuid;
106     }
107
108     /**
109      *
110      * @uml.property name="type"
111      */

112     public String JavaDoc getType() {
113         return type;
114     }
115
116     /**
117      *
118      * @uml.property name="icon"
119      */

120     public String JavaDoc getIcon() {
121         return icon;
122     }
123
124     /**
125      *
126      * @uml.property name="size"
127      */

128     public String JavaDoc getSize() {
129         return size;
130     }
131
132     /**
133      *
134      * @uml.property name="green"
135      */

136     /*public float getScore() {
137      return score;
138      }*/

139
140     public Integer JavaDoc getGreen() {
141         return green;
142     }
143
144     /**
145      *
146      * @uml.property name="red"
147      */

148     public Integer JavaDoc getRed() {
149         return red;
150     }
151
152     /**
153      *
154      * @uml.property name="name"
155      */

156     public void setName(String JavaDoc nme) {
157         name = nme;
158     }
159
160     /**
161      *
162      * @uml.property name="summary"
163      */

164     public void setSummary(String JavaDoc summ) {
165         summary = summ;
166     }
167
168     /**
169      *
170      * @uml.property name="path"
171      */

172     public void setPath(String JavaDoc pth) {
173         path = pth;
174     }
175
176     /**
177      *
178      * @uml.property name="menuid"
179      */

180     public void setMenuid(String JavaDoc id) {
181         menuid = id;
182     }
183     
184     /**
185      * @return Returns the length.
186      * @uml.property name="length"
187      */

188     public Integer JavaDoc getLength() {
189         return length;
190     }
191     
192     /**
193      * @param length The length to set.
194      * @uml.property name="length"
195      */

196     public void setLength(Integer JavaDoc length) {
197         this.length = length;
198     }
199     
200     /**
201      *
202      * @uml.property name="type"
203      */

204     public void setType(String JavaDoc typ) {
205         type = typ;
206         icon = "pages/images/";
207         if (type.equals("PDF"))
208             icon += "pdf.gif";
209         else if (type.equals("DOC")
210             || type.equals("DOT")
211             || type.equals("RTF")
212             || type.equals("SXW")
213             || type.equals("TXT")
214             || type.equals("WPD")
215             || type.equals("KWD")
216             || type.equals("ABW")
217             || type.equals("ZABW")
218             || type.equals("ODT"))
219             icon += "textdoc.gif";
220         else if (type.equals("XLS")
221                 || type.equals("XLT")
222                 || type.equals("SXC")
223                 || type.equals("DBF")
224                 || type.equals("KSP")
225                 || type.equals("ODS")
226                 || type.equals("ODB"))
227             icon += "tabledoc.gif";
228         else if (type.equals("PPT")
229                 || type.equals("PPS")
230                 || type.equals("POT")
231                 || type.equals("SXI")
232                 || type.equals("KPR")
233                 || type.equals("ODP"))
234             icon += "presentdoc.gif";
235         else if (type.equals("APF")
236             || type.equals("BMP")
237             || type.equals("JPEG")
238             || type.equals("DIB")
239             || type.equals("GIF")
240             || type.equals("JPG")
241             || type.equals("PSD")
242             || type.equals("TIF")
243             || type.equals("TIFF"))
244             icon += "picture.gif";
245         else if (type.equals("HTM")
246             || type.equals("HTML")
247             || type.equals("XML"))
248             icon += "internet.gif";
249         else
250             icon += "document.gif";
251     }
252
253     
254     /**
255      * @param icon The icon to set.
256      * @uml.property name="icon"
257      */

258     public void setIcon(String JavaDoc icon) {
259     }
260
261     /**
262      *
263      * @uml.property name="size"
264      */

265     public void setSize(String JavaDoc sze) {
266         size = sze;
267     }
268
269     
270     public void createScore(float score) {
271         float temp = score*100;
272         int tgreen = Math.round(temp);
273         if (tgreen < 1)
274             tgreen = 1;
275         green = new Integer JavaDoc(tgreen);
276         temp = 100-(score*100);
277         int tred = Math.round(temp);
278         if (tred > 99)
279             tred = 99;
280         red = new Integer JavaDoc(tred);
281     }
282
283     /**
284      *
285      * @uml.property name="green"
286      */

287     public void setGreen(Integer JavaDoc grn) {
288         green = grn;
289     }
290
291     /**
292      *
293      * @uml.property name="red"
294      */

295     public void setRed(Integer JavaDoc rd) {
296         red = rd;
297     }
298
299     
300     public boolean isRelevant(SearchOptions opt, String JavaDoc refdate) {
301         boolean result = true;
302         if (opt.getFormat() != null && !opt.getFormat().equals("all")) {
303             if (!type.toLowerCase().equals(opt.getFormat()))
304                 result = false;
305         }
306         if (opt.getLength() != null && !opt.getLength().equals("")) {
307             if (opt.getRelation().equals("gt")) {
308                 if (Integer.parseInt(size) <= Integer.parseInt(opt.getLength()))
309                     result = false;
310             } else {
311                 if (opt.getRelation().equals("lt")) {
312                     if (Integer.parseInt(size) >= Integer.parseInt(opt.getLength()))
313                         result = false;
314                 } else {
315                     if (Integer.parseInt(size) != Integer.parseInt(opt.getLength()))
316                         result = false;
317                 }
318             }
319         }
320         if (opt.getDate() != null && !opt.getDate().equals("")) {
321             long diff = Long.parseLong(refdate) - Long.parseLong(opt.getDate());
322             if (opt.getDateRelation().equals("gt")) {
323                 if (diff >= 0)
324                     result = false;
325             } else {
326                 if (opt.getDateRelation().equals("lt")) {
327                     if (diff <= 0)
328                         result = false;
329                 }
330                 else {
331                     if (diff != 0)
332                         result = false;
333                 }
334             }
335         }
336         return result;
337     }
338     
339     public int getLengthCategory() {
340         int len = length.intValue();
341         if (len > 60000)
342             return 5;
343         if (len > 18000)
344             return 4;
345         if (len > 3000)
346             return 3;
347         if (len > 600)
348             return 2;
349         return 1;
350     }
351     
352     /**
353      * @param date The date to set.
354      * @uml.property name="date"
355      */

356     public void setDate(Date JavaDoc d) {
357         date = d;
358     }
359     
360     /**
361      * @return Returns the date.
362      * @uml.property name="date"
363      */

364     public Date JavaDoc getDate() {
365         return date;
366     }
367     
368     public int getDateCategory() {
369         long diff = new Date JavaDoc().getTime() - date.getTime();
370         long days = diff/1000/60/60/24; // 1000-sec , 60-min , 60-h , 24-day
371
if (days < 8)
372             return 0;
373         if (days < 29)
374             return 1;
375         if (days < 92)
376             return 2;
377         if (days < 366)
378             return 3;
379         return 4;
380     }
381     
382     public int getDocType() {
383         if (type.equals("PDF") || type.equals("DOC") || type.equals("TXT") ||
384                 type.equals("RTF") || type.equals("HTML") || type.equals("HTM") ||
385                 type.equals("SXW") || type.equals("WPD") || type.equals("PS") ||
386                 type.equals("KWD"))
387             return 0;
388         if (type.equals("XLS") || type.equals("SXC") || type.equals("KSP"))
389             return 1;
390         if (type.equals("PPT") || type.equals("PPS") || type.equals("SXI") ||
391                 type.equals("KPR"))
392             return 2;
393         return 3;
394     }
395 }
396
Popular Tags