Source Code Cross Referenced for SearcherBaseImpl.java in  » Search-Engine » snapper » org » enhydra » snapper » business » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Search Engine » snapper » org.enhydra.snapper.business 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.enhydra.snapper.business;
002:
003:        import java.io.File;
004:        import java.io.IOException;
005:        import java.text.ParseException;
006:        import java.text.SimpleDateFormat;
007:        import java.util.ArrayList;
008:        import java.util.Collection;
009:        import java.util.Date;
010:        import java.util.Enumeration;
011:        import java.util.Iterator;
012:        import java.util.Properties;
013:
014:        import org.enhydra.snapper.Snapper;
015:        import org.enhydra.snapper.SnapperManager;
016:        import org.enhydra.snapper.api.Searcher;
017:        import org.enhydra.snapper.api.searching.SearchResult;
018:        import org.enhydra.snapper.spec.SearcherBase;
019:        import org.enhydra.snapper.business.SiteListImpl;
020:        import org.enhydra.snapper.spec.Site;
021:        import org.enhydra.snapper.spec.SiteList;
022:        import org.enhydra.snapper.spec.SiteListFactory;
023:
024:        import com.lutris.logging.Logger;
025:
026:        /**
027:         * @author Milin Radivoj
028:         *
029:         */
030:
031:        public class SearcherBaseImpl implements  SearcherBase {
032:
033:            Searcher searcher;
034:
035:            String defaultIndexDir = Snapper.getIndexDir();
036:
037:            SiteListImpl siteList = new SiteListImpl();
038:
039:            Properties luceneParameters = new Properties();
040:
041:            Properties highlightParameters = new Properties();
042:
043:            Properties requestParameters = new Properties();
044:
045:            String patern = requestParameters.getProperty("searchDatePattern");
046:
047:            boolean mailDatesEither = false;
048:
049:            public void setUpSearcher(Properties sitesIDs, Mapper mapper) {
050:                try {
051:                    Properties prop = new Properties();
052:
053:                    for (Enumeration e = sitesIDs.propertyNames(); e
054:                            .hasMoreElements();) {
055:
056:                        String siteName = (String) e.nextElement();
057:
058:                        String indexDir = null;
059:                        try {
060:                            SiteList sl = SiteListFactory
061:                                    .getSiteList("org.enhydra.snapper.business.SiteListImpl");
062:                            Site[] sites = sl.getList();
063:
064:                            if (sites != null) {
065:                                for (int i = 0; i < sites.length; i++) {
066:                                    if (sites[i] != null
067:                                            && sites[i].getNAME().equals(
068:                                                    siteName)) {
069:                                        indexDir = sites[i].getINDEXDIR();
070:                                        break;
071:                                    }
072:                                }
073:                            }
074:
075:                        } catch (Exception exx) {
076:                            try {
077:                                Snapper.getLogChanel().write(
078:                                        Logger.WARNING,
079:                                        "Could not get index directory for site Name : "
080:                                                + siteName + " \n caught a "
081:                                                + e.getClass()
082:                                                + "\n with message: "
083:                                                + exx.getMessage());
084:                            } catch (Exception ex) {
085:                                System.out.println(" caught a " + e.getClass()
086:                                        + "\n with message: "
087:                                        + exx.getMessage());
088:                            }
089:                        }
090:
091:                        File temp;
092:
093:                        if (indexDir != null && !indexDir.equals("")) {
094:                            temp = new File(indexDir);
095:                        } else {
096:                            if (defaultIndexDir.endsWith("\\")
097:                                    || defaultIndexDir.endsWith("/"))
098:                                temp = new File(defaultIndexDir + siteName);
099:                            else
100:                                temp = new File(defaultIndexDir
101:                                        + File.separator + siteName);
102:                        }
103:
104:                        if (temp.isDirectory()) {
105:
106:                            prop.setProperty(siteName, temp.getAbsolutePath());
107:
108:                        } else {/*
109:                        				 try{
110:                        				 Snapper.getLogChanel().write(Logger.WARNING, "Site : "+siteName+" with path "+temp.getAbsolutePath()+" is not directory , will not be searched ");
111:                        				 } catch (Exception ex) {
112:                        				 System.out.println(" caught a " + ex.getClass() +
113:                        				 "\n with message: " + ex.getMessage());
114:                        				 }
115:                         */
116:                        }
117:                    }
118:                    try {
119:                        IncrementQueryNumber.increment(sitesIDs);
120:                    } catch (Exception ex) {
121:                    }
122:                    searcher = SnapperManager.getInstance()
123:                            .getSearcherFactory().newSearcher();
124:                    searcher.setUpSearcher(prop);
125:
126:                } catch (Exception e) {
127:                    Snapper.getLogChanel().write(
128:                            Logger.ERROR,
129:                            "Could not setup Searcher caught a " + e.getClass()
130:                                    + "\n with message: " + e.getMessage());
131:                }
132:
133:            }
134:
135:            String sentDate = null;
136:
137:            public void setUpSearcherQuery(Properties requestParameters) {
138:                this .requestParameters = requestParameters;
139:                String modfrom = requestParameters.getProperty("modifiedfrom");
140:                String modto = requestParameters.getProperty("modifiedto");
141:
142:                String createdfrom = requestParameters
143:                        .getProperty("createdfrom");
144:                String createdto = requestParameters.getProperty("createdto");
145:
146:                String acesedfrom = requestParameters
147:                        .getProperty("accessedfrom");
148:                String acesedto = requestParameters.getProperty("accessedto");
149:
150:                String sentDatefrom = requestParameters
151:                        .getProperty("sentDatefrom");
152:                String sentDateto = requestParameters.getProperty("sentDateto");
153:
154:                String receivedDatefrom = requestParameters
155:                        .getProperty("receivedDatefrom");
156:                String receivedDateto = requestParameters
157:                        .getProperty("receivedDateto");
158:
159:                String wordKew = requestParameters.getProperty("propertiesKey");
160:                String wordValue = requestParameters
161:                        .getProperty("propertiesValue");
162:
163:                String metaDataKey = requestParameters
164:                        .getProperty("metaDataKey");
165:                String metaDataValue = requestParameters
166:                        .getProperty("metaDataValue");
167:
168:                String owner = requestParameters.getProperty("owner");
169:                String author = requestParameters.getProperty("author");
170:                ;
171:                String lastsavedby = requestParameters
172:                        .getProperty("lastsavedby");
173:                ;
174:
175:                String subject = requestParameters.getProperty("subject");
176:                String mailFrom = requestParameters.getProperty("mailFrom");
177:                String mailTo = requestParameters.getProperty("mailTo");
178:                String mailCC = requestParameters.getProperty("mailCC");
179:                String mailBCC = requestParameters.getProperty("mailBCC");
180:
181:                String properties = null;
182:                String modified = null;
183:                String created = null;
184:                String accessed = null;
185:
186:                String receivedDate = null;
187:                String metaData = null;
188:
189:                if (wordKew != null && !wordKew.equals("") && wordValue != null
190:                        && !wordValue.equals("")) {
191:                    properties = "\"" + wordKew + " = " + wordValue + "\"";
192:                } else {
193:                    if (wordKew != null && !wordKew.equals("")) {
194:                        properties = "\"" + wordKew + "\"";
195:                    } else if (wordValue != null && !wordValue.equals("")) {
196:                        properties = "\"" + wordValue + "\"";
197:                    }
198:                }
199:
200:                if (metaDataKey != null && !metaDataKey.equals("")
201:                        && metaDataValue != null && !metaDataValue.equals("")) {
202:                    metaData = "\"" + metaDataKey + " = " + metaDataValue
203:                            + "\"";
204:                } else {
205:                    if (metaDataKey != null && !metaDataKey.equals("")) {
206:                        metaData = "\"" + metaDataKey + "\"";
207:                    } else if (metaDataValue != null
208:                            && !metaDataValue.equals("")) {
209:                        metaData = "\"" + metaDataValue + "\"";
210:                    }
211:                }
212:
213:                if (patern == null)
214:                    patern = Snapper.getSearchDatePattern();
215:
216:                if ((modfrom != null && !modfrom.equals(""))
217:                        || (modto != null && !modto.equals(""))) {
218:                    try {
219:                        if ((modfrom != null && !modfrom.equals(""))
220:                                && (modto != null && !modto.equals(""))) {
221:                            String conFrom = null;
222:
223:                            if (modfrom != null && !modfrom.equals("="))
224:                                conFrom = convertDate(modfrom, patern);
225:
226:                            String conTo = null;
227:
228:                            if (modto != null && !modto.equals("="))
229:                                conTo = convertDate(modto, patern);
230:
231:                            if (conFrom != null && conTo != null)
232:                                modified = "[" + conFrom + " TO " + conTo + "]";
233:                            else if (conFrom != null)
234:                                modified = conFrom;
235:                            else if (conTo != null)
236:                                modified = conTo;
237:
238:                        } else if (modfrom != null && !modfrom.equals("")) {
239:
240:                            Date datefromDate = new Date(System
241:                                    .currentTimeMillis());
242:                            SimpleDateFormat outformatter = new SimpleDateFormat(
243:                                    patern);
244:                            modto = outformatter.format(datefromDate);
245:
246:                            String conFrom = convertDate(modfrom, patern);
247:                            String conTo = convertDate(modto, patern);
248:
249:                            if (conFrom != null && conTo != null)
250:                                modified = "[" + conFrom + " TO " + conTo + "]";
251:
252:                        } else if (modto != null && !modto.equals("")) {
253:
254:                            Date datefromDate = (new Date(0));
255:                            SimpleDateFormat outformatter = new SimpleDateFormat(
256:                                    patern);
257:                            modfrom = outformatter.format(datefromDate);
258:
259:                            String conFrom = convertDate(modfrom, patern);
260:                            String conTo = convertDate(modto, patern);
261:
262:                            if (conFrom != null && conTo != null)
263:                                modified = "[" + conFrom + " TO " + conTo + "]";
264:                        }
265:                    } catch (Exception e) {
266:                        Snapper.getLogChanel().write(
267:                                Logger.WARNING,
268:                                "Problem in creaton query for mail sent date "
269:                                        + e.getClass() + "\n with message: "
270:                                        + e.getMessage());
271:                    }
272:                }
273:
274:                if ((createdfrom != null && !createdfrom.equals(""))
275:                        || (createdto != null && !createdto.equals(""))) {
276:                    try {
277:                        if ((createdfrom != null && !createdfrom.equals(""))
278:                                && (createdto != null && !createdto.equals(""))) {
279:                            String conFrom = null;
280:
281:                            if (createdfrom != null && !createdfrom.equals("="))
282:                                conFrom = convertDate(createdfrom, patern);
283:
284:                            String conTo = null;
285:
286:                            if (createdto != null && !createdto.equals("="))
287:                                conTo = convertDate(createdto, patern);
288:
289:                            if (conFrom != null && conTo != null)
290:                                created = "[" + conFrom + " TO " + conTo + "]";
291:                            else if (conFrom != null)
292:                                created = conFrom;
293:                            else if (conTo != null)
294:                                created = conTo;
295:
296:                        } else if (createdfrom != null
297:                                && !createdfrom.equals("")) {
298:
299:                            Date datefromDate = new Date(System
300:                                    .currentTimeMillis());
301:                            SimpleDateFormat outformatter = new SimpleDateFormat(
302:                                    patern);
303:                            createdto = outformatter.format(datefromDate);
304:
305:                            String conFrom = convertDate(createdfrom, patern);
306:                            String conTo = convertDate(createdto, patern);
307:
308:                            if (conFrom != null && conTo != null)
309:                                created = "[" + conFrom + " TO " + conTo + "]";
310:
311:                        } else if (createdto != null && !createdto.equals("")) {
312:
313:                            Date datefromDate = (new Date(0));
314:                            SimpleDateFormat outformatter = new SimpleDateFormat(
315:                                    patern);
316:                            createdfrom = outformatter.format(datefromDate);
317:
318:                            String conFrom = convertDate(createdfrom, patern);
319:                            String conTo = convertDate(createdto, patern);
320:
321:                            if (conFrom != null && conTo != null)
322:                                created = "[" + conFrom + " TO " + conTo + "]";
323:                        }
324:                    } catch (Exception e) {
325:                        Snapper.getLogChanel().write(
326:                                Logger.WARNING,
327:                                "Problem in creaton query for mail sent date "
328:                                        + e.getClass() + "\n with message: "
329:                                        + e.getMessage());
330:                    }
331:                }
332:
333:                if ((acesedfrom != null && !acesedfrom.equals(""))
334:                        || (acesedto != null && !acesedto.equals(""))) {
335:                    try {
336:                        if ((acesedfrom != null && !acesedfrom.equals(""))
337:                                && (acesedto != null && !acesedto.equals(""))) {
338:                            String conFrom = null;
339:
340:                            if (acesedfrom != null && !acesedfrom.equals("="))
341:                                conFrom = convertDate(acesedfrom, patern);
342:
343:                            String conTo = null;
344:
345:                            if (acesedto != null && !acesedto.equals("="))
346:                                conTo = convertDate(acesedto, patern);
347:
348:                            if (conFrom != null && conTo != null)
349:                                accessed = "[" + conFrom + " TO " + conTo + "]";
350:                            else if (conFrom != null)
351:                                accessed = conFrom;
352:                            else if (conTo != null)
353:                                accessed = conTo;
354:
355:                        } else if (acesedfrom != null && !acesedfrom.equals("")) {
356:
357:                            Date datefromDate = new Date(System
358:                                    .currentTimeMillis());
359:                            SimpleDateFormat outformatter = new SimpleDateFormat(
360:                                    patern);
361:                            acesedto = outformatter.format(datefromDate);
362:
363:                            String conFrom = convertDate(acesedfrom, patern);
364:                            String conTo = convertDate(acesedto, patern);
365:
366:                            if (conFrom != null && conTo != null)
367:                                accessed = "[" + conFrom + " TO " + conTo + "]";
368:
369:                        } else if (acesedto != null && !acesedto.equals("")) {
370:
371:                            Date datefromDate = (new Date(0));
372:                            SimpleDateFormat outformatter = new SimpleDateFormat(
373:                                    patern);
374:                            acesedfrom = outformatter.format(datefromDate);
375:
376:                            String conFrom = convertDate(acesedfrom, patern);
377:                            String conTo = convertDate(acesedto, patern);
378:
379:                            if (conFrom != null && conTo != null)
380:                                accessed = "[" + conFrom + " TO " + conTo + "]";
381:                        }
382:                    } catch (Exception e) {
383:                        Snapper.getLogChanel().write(
384:                                Logger.WARNING,
385:                                "Problem in creaton query for mail sent date "
386:                                        + e.getClass() + "\n with message: "
387:                                        + e.getMessage());
388:                    }
389:                }
390:
391:                if ((sentDatefrom != null && !sentDatefrom.equals(""))
392:                        || (sentDateto != null && !sentDateto.equals(""))) {
393:                    try {
394:                        if ((sentDatefrom != null && !sentDatefrom.equals(""))
395:                                && (sentDateto != null && !sentDateto
396:                                        .equals(""))) {
397:                            String conFrom = null;
398:
399:                            if (sentDatefrom != null
400:                                    && !sentDatefrom.equals("="))
401:                                conFrom = convertMailDate(sentDatefrom, patern);
402:
403:                            String conTo = null;
404:
405:                            if (sentDateto != null && !sentDateto.equals("="))
406:                                conTo = convertMailDate(sentDateto, patern);
407:
408:                            if (conFrom != null && conTo != null)
409:                                sentDate = "[" + conFrom + " TO " + conTo + "]";
410:                            else if (conFrom != null)
411:                                sentDate = conFrom;
412:                            else if (conTo != null)
413:                                sentDate = conTo;
414:
415:                        } else if (sentDatefrom != null
416:                                && !sentDatefrom.equals("")) {
417:
418:                            Date datefromDate = new Date(System
419:                                    .currentTimeMillis());
420:                            SimpleDateFormat outformatter = new SimpleDateFormat(
421:                                    patern);
422:                            sentDateto = outformatter.format(datefromDate);
423:
424:                            String conFrom = convertMailDate(sentDatefrom,
425:                                    patern);
426:                            String conTo = convertMailDate(sentDateto, patern);
427:
428:                            if (conFrom != null && conTo != null)
429:                                sentDate = "[" + conFrom + " TO " + conTo + "]";
430:
431:                        } else if (sentDateto != null && !sentDateto.equals("")) {
432:
433:                            Date datefromDate = (new Date(0));
434:                            SimpleDateFormat outformatter = new SimpleDateFormat(
435:                                    patern);
436:                            sentDatefrom = outformatter.format(datefromDate);
437:
438:                            String conFrom = convertMailDate(sentDatefrom,
439:                                    patern);
440:                            String conTo = convertMailDate(sentDateto, patern);
441:
442:                            if (conFrom != null && conTo != null)
443:                                sentDate = "[" + conFrom + " TO " + conTo + "]";
444:                        }
445:                    } catch (Exception e) {
446:                        Snapper.getLogChanel().write(
447:                                Logger.WARNING,
448:                                "Problem in creaton query for mail sent date "
449:                                        + e.getClass() + "\n with message: "
450:                                        + e.getMessage());
451:                    }
452:                }
453:
454:                if ((receivedDatefrom != null && !receivedDatefrom.equals(""))
455:                        || (receivedDateto != null && !receivedDateto
456:                                .equals(""))) {
457:                    try {
458:                        if ((receivedDatefrom != null && !receivedDatefrom
459:                                .equals(""))
460:                                && (receivedDateto != null && !receivedDateto
461:                                        .equals(""))) {
462:                            String conFrom = null;
463:
464:                            if (receivedDatefrom != null
465:                                    && !receivedDatefrom.equals("="))
466:                                conFrom = convertMailDate(receivedDatefrom,
467:                                        patern);
468:
469:                            String conTo = null;
470:
471:                            if (receivedDateto != null
472:                                    && !receivedDateto.equals("="))
473:                                conTo = convertMailDate(receivedDateto, patern);
474:
475:                            if (conFrom != null && conTo != null)
476:                                receivedDate = "[" + conFrom + " TO " + conTo
477:                                        + "]";
478:                            else if (conFrom != null)
479:                                receivedDate = conFrom;
480:                            else if (conTo != null)
481:                                receivedDate = conTo;
482:
483:                        } else if (receivedDatefrom != null
484:                                && !receivedDatefrom.equals("")) {
485:
486:                            Date datefromDate = new Date(System
487:                                    .currentTimeMillis());
488:                            SimpleDateFormat outformatter = new SimpleDateFormat(
489:                                    patern);
490:                            receivedDateto = outformatter.format(datefromDate);
491:
492:                            String conFrom = convertMailDate(receivedDatefrom,
493:                                    patern);
494:                            String conTo = convertMailDate(receivedDateto,
495:                                    patern);
496:
497:                            if (conFrom != null && conTo != null)
498:                                receivedDate = "[" + conFrom + " TO " + conTo
499:                                        + "]";
500:
501:                        } else if (receivedDateto != null
502:                                && !receivedDateto.equals("")) {
503:
504:                            Date datefromDate = (new Date(0));
505:                            SimpleDateFormat outformatter = new SimpleDateFormat(
506:                                    patern);
507:                            receivedDatefrom = outformatter
508:                                    .format(datefromDate);
509:
510:                            String conFrom = convertMailDate(receivedDatefrom,
511:                                    patern);
512:                            String conTo = convertMailDate(receivedDateto,
513:                                    patern);
514:
515:                            if (conFrom != null && conTo != null)
516:                                receivedDate = "[" + conFrom + " TO " + conTo
517:                                        + "]";
518:                        }
519:                    } catch (Exception e) {
520:                        Snapper.getLogChanel().write(
521:                                Logger.WARNING,
522:                                "Problem in creaton query for mail sent date "
523:                                        + e.getClass() + "\n with message: "
524:                                        + e.getMessage());
525:                    }
526:                }
527:
528:                if (sentDate != null && !sentDate.equals("")
529:                        && receivedDate != null && !receivedDate.equals(""))
530:                    mailDatesEither = true;
531:
532:                if (requestParameters.containsKey("type")) {
533:                    if (!requestParameters.getProperty("type").equals(""))
534:                        luceneParameters.setProperty("type", requestParameters
535:                                .getProperty("type"));
536:                }
537:
538:                if (requestParameters.containsKey("contents")) {
539:                    if (!requestParameters.getProperty("contents").equals(""))
540:                        luceneParameters.setProperty("contents",
541:                                requestParameters.getProperty("contents"));
542:                }
543:
544:                if (owner != null) {
545:                    if (!owner.equals(""))
546:                        luceneParameters.setProperty("owner", owner);
547:                }
548:
549:                if (subject != null) {
550:                    if (!subject.equals(""))
551:                        luceneParameters.setProperty("subject", subject);
552:                }
553:
554:                if (author != null) {
555:                    if (!author.equals(""))
556:                        luceneParameters.setProperty("author", author);
557:                }
558:
559:                if (lastsavedby != null) {
560:                    if (!lastsavedby.equals(""))
561:                        luceneParameters
562:                                .setProperty("lastsavedby", lastsavedby);
563:                }
564:                if (mailFrom != null) {
565:                    if (!mailFrom.equals(""))
566:                        luceneParameters.setProperty("from", mailFrom);
567:                }
568:                if (mailTo != null) {
569:                    if (!mailTo.equals(""))
570:                        luceneParameters.setProperty("to", mailTo);
571:                }
572:
573:                if (mailCC != null) {
574:                    if (!mailCC.equals(""))
575:                        luceneParameters.setProperty("cc", mailCC);
576:                }
577:                if (mailBCC != null) {
578:                    if (!mailBCC.equals(""))
579:                        luceneParameters.setProperty("bcc", mailBCC);
580:                }
581:
582:                if (requestParameters.containsKey("title")) {
583:                    if (!requestParameters.getProperty("title").equals(""))
584:                        luceneParameters.setProperty("title", requestParameters
585:                                .getProperty("title"));
586:                }
587:
588:                if (properties != null) {
589:                    luceneParameters.setProperty("properties", properties);
590:                }
591:
592:                if (metaData != null) {
593:                    luceneParameters.setProperty("metadata", metaData);
594:                }
595:
596:                if (modified != null) {
597:                    luceneParameters.setProperty("modified", modified);
598:                }
599:
600:                if (created != null) {
601:                    luceneParameters.setProperty("created", created);
602:                }
603:
604:                if (accessed != null) {
605:                    luceneParameters.setProperty("access", accessed);
606:                }
607:
608:                if (sentDate != null) {
609:                    luceneParameters.setProperty("mailSentDate", sentDate);
610:                }
611:
612:                if (receivedDate != null) {
613:                    luceneParameters.setProperty("mailReceivedDate",
614:                            receivedDate);
615:                }
616:
617:                String contentLength = requestParameters
618:                        .getProperty("contentLength");
619:                String wordLength = requestParameters.getProperty("wordLength");
620:                String metaDataLength = requestParameters
621:                        .getProperty("metaDataLength");
622:
623:                if (contentLength != null)
624:                    highlightParameters.setProperty("contentLength",
625:                            contentLength);
626:
627:                if (wordLength != null)
628:                    highlightParameters.setProperty("wordLength", wordLength);
629:
630:                if (metaDataLength != null)
631:                    highlightParameters.setProperty("metaDataLength",
632:                            metaDataLength);
633:
634:                if (Snapper.getHighlightFuzzyQuery().equals("false"))
635:                    highlightParameters.setProperty("highlightFuzzyQuery",
636:                            "false");
637:
638:            }
639:
640:            public void setUpHighLighter(Properties prop) {
641:
642:                //searcher.setUpHighLighter(prop);
643:            }
644:
645:            public void searchDocs() throws IOException {
646:                try {
647:
648:                    String query = luceneQuery();
649:
650:                    String filter = "";
651:
652:                    String groupMail = requestParameters
653:                            .getProperty("groupMail");
654:
655:                    /*if(groupMail!=null && groupMail.equals("sent") && sentDate!=null)
656:                     {
657:                     filter = "mailReceivedDate";
658:                     }*/
659:
660:                    searcher.searchDocs(query, luceneParameters
661:                            .getProperty("contents"), luceneParameters
662:                            .getProperty("properties"), luceneParameters
663:                            .getProperty("metadata"), requestParameters
664:                            .getProperty("sortType"), filter);
665:                } catch (Exception e) {
666:                    throw new IOException(e.getMessage());
667:                }
668:
669:                searcher.setUpHighLighter(highlightParameters);
670:            }
671:
672:            public int getSearchedDocsNumber() {
673:                return searcher.getSearchedDocsNumber();
674:            }
675:
676:            public SearchResult getSearchResult(int begin, int end) {
677:                return searcher.getSearchResult(begin, end);
678:            }
679:
680:            public SearchResult getSearchResult() {
681:                return searcher.getSearchResult();
682:            }
683:
684:            public void close() {
685:                try {
686:                    searcher.close();
687:                } catch (Exception e) {
688:                    Snapper.getLogChanel().write(
689:                            Logger.ERROR,
690:                            "Could not close searcher  \n caught a "
691:                                    + e.getClass() + "\n with message: "
692:                                    + e.getMessage());
693:                }
694:                searcher = null;
695:                SnapperManager.getInstance().getSearcherFactory()
696:                        .removeSearcher();
697:            }
698:
699:            public String luceneQuery() {
700:
701:                StringBuffer luceneQuery = new StringBuffer();
702:                boolean set = false;
703:
704:                for (Enumeration e = luceneParameters.propertyNames(); e
705:                        .hasMoreElements();) {
706:                    String field = (String) e.nextElement();
707:                    String query = (String) luceneParameters.getProperty(field);
708:
709:                    if (mailDatesEither && !set) {
710:                        String querySent = (String) luceneParameters
711:                                .getProperty("mailSentDate");
712:                        String queryReceived = (String) luceneParameters
713:                                .getProperty("mailReceivedDate");
714:
715:                        luceneQuery.append("(mailSentDate:(" + querySent
716:                                + ") OR mailReceivedDate:(" + queryReceived
717:                                + "))");
718:                        set = true;
719:                    }
720:
721:                    if (e.hasMoreElements()) {
722:                        if (!mailDatesEither
723:                                || ((!field.equals("mailSentDate")) && (!field
724:                                        .equals("mailReceivedDate"))))
725:                            if (!set)
726:                                luceneQuery.append(field + ":(" + query
727:                                        + ") AND ");
728:                            else
729:                                luceneQuery.append(" AND " + field + ":("
730:                                        + query + ")");
731:                    } else {
732:                        if (!mailDatesEither
733:                                || ((!field.equals("mailSentDate")) && (!field
734:                                        .equals("mailReceivedDate"))))
735:                            luceneQuery.append(field + ":(" + query + ")");
736:                    }
737:                }
738:                return luceneQuery.toString();
739:            }
740:
741:            public String convertDate(String date, String patern) {
742:                String result;
743:                SimpleDateFormat outformatter = new SimpleDateFormat("yyyyMMdd");
744:                SimpleDateFormat in = new SimpleDateFormat(patern);
745:
746:                try {
747:                    Date d = in.parse(date);
748:                    result = outformatter.format(d);
749:                } catch (ParseException e) {
750:                    Snapper.getLogChanel().write(
751:                            Logger.WARNING,
752:                            "Problem in input field  \n caught a "
753:                                    + e.getClass() + "\n with message: "
754:                                    + e.getMessage());
755:                    return null;
756:                }
757:
758:                return result;
759:
760:            }
761:
762:            public String convertMailDate(String date, String patern) {
763:                String result;
764:                SimpleDateFormat outformatter = new SimpleDateFormat("yyyyMMdd");
765:                SimpleDateFormat in = new SimpleDateFormat(patern);
766:
767:                try {
768:                    Date d = in.parse(date);
769:                    result = outformatter.format(d);
770:                } catch (ParseException e) {
771:                    Snapper.getLogChanel().write(
772:                            Logger.WARNING,
773:                            "Problem in input field  \n caught a "
774:                                    + e.getClass() + "\n with message: "
775:                                    + e.getMessage());
776:                    return null;
777:                }
778:
779:                return result;
780:
781:            }
782:
783:            public boolean isMailDatesEither() {
784:                return mailDatesEither;
785:            }
786:
787:            public void setMailDatesEither(boolean mailDatesEither) {
788:                this.mailDatesEither = mailDatesEither;
789:            }
790:
791:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.