001: package com.sun.portal.search;
002:
003: import java.util.*;
004: import java.util.logging.Logger;
005: import java.util.logging.Level;
006: import java.lang.*;
007:
008: import soif.*;
009: import com.sun.portal.providers.jsp.JSPProvider;
010: import com.sun.portal.log.common.PortalLogger;
011:
012: /**
013: * This class providers a bean wrapper interface
014: * for the <code> Search </code> class.
015: * <p>
016: * @see soif.Search
017: */
018: public class SearchRequestBean {
019:
020: private static final int BASIC = 1;
021: public static final int ADVANCED = 2;
022: public static final int CATEGORY = 3;
023: public static final int BROWSE = 4;
024:
025: private static Logger debugLogger = PortalLogger
026: .getLogger(SearchRequestBean.class);
027:
028: /******************************************************************
029: *
030: * Search parameters
031: *
032: *****************************************************************/
033:
034: /*
035: * The default values for rdmServer, viewAttributes, viewOrder,
036: * viewHits are retrieved from DS/AME. These defaults can be modified
037: * in the JSP's
038: */
039: private JSPProvider provider = null;
040: private String rdmServer = "";
041: private String viewAttributes = "url,title,description,score,id";
042: private String viewOrder = "";
043: private int viewHits = 8;
044:
045: /*
046: * The default values for rdmType, queryLanguage, fromHit
047: * are hardcoded in the bean. New values can be set in the JSP
048: */
049: private String rdmType = "rd-request";
050: private String queryLanguage = "compass";
051: private int fromHit = 1;
052: private String scope = null;
053:
054: /******************************************************************
055: * These are Session variables in the JSP and are
056: * passed around as HTML hidden attributes. They
057: * are temporarily stored in the request Bean for
058: * convenient data access and data manipulation
059: * within the Bean object
060: ******************************************************************/
061: private int page = 1;
062: private String description = "brief";
063: private String mode = "basic";
064: private int searchType = this .BASIC;
065: private String browseCategory = "anklebiter ROOT";
066:
067: /******************************************************************
068: *
069: * Advanced Search specific parameters
070: *
071: *****************************************************************/
072: private String wordsOp = "";
073: private String wordsVal = "";
074:
075: private String nowords = "";
076:
077: private String vhits = "";
078:
079: private String urlOp = "";
080: private String urlVal = "";
081:
082: private String since = "";
083:
084: private String authorOp = "";
085: private String authorVal = "";
086:
087: private String comments = "";
088:
089: private String titleOp = "";
090: private String titleVal = "";
091:
092: private String keywordsOp = "";
093: private String keywordsVal = "";
094:
095: private String expiresOp = "";
096: private String expiresVal = "";
097:
098: private String lmodifiedOp = "";
099: private String lmodifiedVal = "";
100:
101: /******************************************************************
102: *
103: * Search Results related variables
104: * Some of the values are computed at the end of each search.execute()
105: *
106: *****************************************************************/
107: private Search search = null;
108: private SOIF soifResults = null;
109:
110: private int totalCount = 0;
111: private int resultCount = 0;
112: private int totalPages = 0;
113: private int taxonomyHits = 0;
114:
115: /*
116: * Boolean properties related to search Results
117: * These have been mainly defined in order to make the JSP to
118: * Bean communication simple
119: */
120: private boolean categorySearch = false;
121: private boolean moreThanOne = false;
122: private boolean next = false;
123: private boolean previous = false;
124: private boolean moreHits = false;
125: private int nextPage;
126: private int previousPage;
127:
128: /******************************************************************
129: *
130: * Properties used for debugging
131: *
132: *****************************************************************/
133: private String soifString = null;
134: private String searchString = null;
135:
136: /******************************************************************
137: *
138: * TBD: Static messages for i18n, should be moved to
139: * resource bundles or moved to the JSP
140: *
141: *****************************************************************/
142: private String matchesFoundMsg = "";
143: private String noMatchesFoundMsg = "";
144: private String categoryMatchesFoundMsg = "";
145: private String noCategoryMatchesFoundMsg = "";
146: private String hiddenMessage = "";
147:
148: /*
149: * Constructor
150: */
151: public void SearchRequestBean() {
152: }
153:
154: /*
155: * @param Provider object which allows the bean to access iPS backend
156: * PageContext provider object is stored in the bean
157: * This allows the bean to access iPS resources
158: */
159: public void setProvider(JSPProvider p) {
160: this .provider = p;
161:
162: this .description = p.getStringProperty("desc", "description");
163: // Get default search params from iPS store
164: // rdmServer, viewHits, searchType, viewAttributes, viewOrder,
165: // rdmType, queryLanguage
166: this .rdmServer = p
167: .getStringProperty("compassServer", "http://");
168: this .viewHits = Integer.parseInt(p.getStringProperty(
169: "hitNumber", "1"));
170: String tmp = p.getStringProperty("basicSearchDefault", "false");
171: if (tmp.equals("true"))
172: this .searchType = BASIC;
173: else
174: this .searchType = ADVANCED;
175: }
176:
177: /*********************************************************************
178: *
179: * Search Constructor parameters
180: * Default values for these are hardcoded in the bean
181: *
182: ********************************************************************/
183:
184: /*
185: * @param server The compass server URL
186: * Default value is picked from DS/AME
187: */
188: public void setRdmServer(String server) {
189: this .rdmServer = server;
190: }
191:
192: /*
193: * Constructor parameter
194: * @param rdmType Default value is 'rd-request'
195: * rdmType can have the following values: 'rd-request',
196: * 'taxonomy-request', 'status-request', 'schema-request',
197: * 'server-request'
198: */
199: public void setRdmType(String type) {
200: this .rdmType = type;
201: }
202:
203: /*
204: * Constructor parameter
205: * @param queryLanguage Default value is "compass"
206: * ql can have the following values: 'compass', 'gatherer'
207: * 'classification', 'taxonomy-basic', 'url'
208: */
209: public void setQueryLanguage(String ql) {
210: this .queryLanguage = ql;
211: }
212:
213: /*
214: * @return value of the starting search match being returned
215: */
216: public int getFromHit() {
217: return fromHit;
218: }
219:
220: /*
221: * Constructor parameter
222: * @param fromHit The first matched document, default to 1
223: */
224: public void setFromHit(int fr) {
225: this .fromHit = fr;
226: }
227:
228: /*********************************************************************
229: *
230: * Search Constructor parameters
231: * Default values for these config params are taken from DS/AME
232: *
233: ********************************************************************/
234:
235: /*
236: * @return The number of hits to be viewed in the results page
237: */
238: public int getViewHits() {
239: return viewHits;
240: }
241:
242: /*
243: * Constructor parameter
244: * @param vhits The number of results to be displayed on the page
245: * Default value is picked from iPS store. The default value can
246: * be replaced by the use of this method.
247: */
248: public void setViewHits(int vhits) {
249: this .viewHits = vhits;
250: }
251:
252: /*
253: * Constructor parameter
254: * @param viewAttributes The comma delimited desired result attributes
255: * Default value is picked from iPS store. The default value is set
256: * when the provider object is set in the bean and can be replaced by
257: * the use of this method.
258: */
259: public void setViewAttributes(String vattr) {
260: this .viewAttributes = vattr;
261: }
262:
263: /*
264: * Constructor parameter
265: * @param viewOrder The comma delimited sort order with +/ascend and -/descend
266: */
267: public void setViewOrder(String vOrder) {
268: this .viewOrder = vOrder;
269: }
270:
271: /***********************************************************
272: *
273: * Session attributes which are passed to the bean in
274: * the request object.
275: *
276: ***********************************************************/
277:
278: /*
279: * @return the scope value
280: */
281: public String getScope() {
282: return scope;
283: }
284:
285: /*
286: * Constructor parameter
287: * @param scope is the query string
288: */
289: public void setScope(String s) {
290: // format scope if required
291: this .scope = s;
292: }
293:
294: public String getDescription() {
295: return description;
296: }
297:
298: /*
299: * @param description length for the search results
300: * This property is related to display cycle. Possible
301: * values can be 'full', 'brief' or 'title'.
302: */
303: public void setDescription(String d) {
304: this .description = d + " description";
305: }
306:
307: /*
308: * @param set the current page value
309: */
310: public void setPage(int p) {
311: this .page = p;
312: }
313:
314: /*
315: * Method to set the search mode
316: * Default is 'basic' search
317: * 'advanced' search is another search option.
318: */
319: public String getMode() {
320: return mode;
321: }
322:
323: /*
324: * @param value of the current search mode
325: * possible values can be 'adv' or 'basic'
326: */
327: public void setMode(String mode) {
328: this .mode = mode;
329: if (mode.equals("adv"))
330: searchType = ADVANCED;
331: }
332:
333: /*
334: * Method for category browsing
335: * @return the current category which is
336: * being browsed
337: */
338:
339: public String getBrowseCategory() {
340: return browseCategory;
341: }
342:
343: /*
344: * @param category to be browsed, If the category is not set
345: * then the category is set to the root of the taxonomy tree
346: */
347: public void setBrowseCategory(String bc) {
348: if (!bc.equals("")) {
349: if (bc.equals("taxonomy")) {
350: this .browseCategory = "anklebiter ROOT";
351: } else {
352: this .browseCategory = "anklebiter " + bc;
353: }
354: searchType = BROWSE;
355: rdmType = "taxonomy-request";
356: queryLanguage = "taxonomy-basic";
357: }
358: }
359:
360: public int getSearchType() {
361: return searchType;
362: }
363:
364: /***********************************************************
365: *
366: * Methods related to advanced search
367: *
368: ***********************************************************/
369: public String getWordsOp() {
370: return wordsOp;
371: }
372:
373: public void setWordsOp(String wordsOperator) {
374: this .wordsOp = wordsOperator;
375: }
376:
377: public String getWordsVal() {
378: return wordsVal;
379: }
380:
381: public void setWordsVal(String whichwords) {
382: this .wordsVal = whichwords;
383: }
384:
385: /*
386: */
387: public String getNowords() {
388: return nowords;
389: }
390:
391: public void setNowords(String nowords) {
392: this .nowords = nowords;
393: }
394:
395: /*
396: */
397: public String getAuthorOp() {
398: return authorOp;
399: }
400:
401: public void setAuthorOp(String authorOperator) {
402: this .authorOp = authorOperator;
403: }
404:
405: public String getAuthorVal() {
406: return authorVal;
407: }
408:
409: public void setAuthorVal(String authorValue) {
410: this .authorVal = authorValue;
411: }
412:
413: /*
414: */
415: public void setUrlOp(String urlOperator) {
416: this .urlOp = urlOperator;
417: }
418:
419: public String getUrlVal() {
420: return urlVal;
421: }
422:
423: public void setUrlVal(String url) {
424: this .urlVal = url;
425: }
426:
427: /*
428: */
429: public void setTitleOp(String titleOperator) {
430: this .titleOp = titleOperator;
431: }
432:
433: public String getTitleVal() {
434: return titleVal;
435: }
436:
437: public void setTitleVal(String title) {
438: this .titleVal = title;
439: }
440:
441: /*
442: */
443: public void setKeywordsOp(String keywordsOperator) {
444: this .keywordsOp = keywordsOperator;
445: }
446:
447: public String getKeywordsVal() {
448: return keywordsVal;
449: }
450:
451: public void setKeywordsVal(String keywords) {
452: this .keywordsVal = keywords;
453: }
454:
455: /*
456: */
457: public void setExpiresOp(String expiresOperator) {
458: this .expiresOp = expiresOperator;
459: }
460:
461: public String getExpiresVal() {
462: return expiresVal;
463: }
464:
465: public void setExpiresVal(String expires) {
466: this .expiresVal = expires;
467: }
468:
469: /*
470: */
471: public void setLmodifiedOp(String lmodifiedOperator) {
472: this .lmodifiedOp = lmodifiedOperator;
473: }
474:
475: public String getLmodifiedVal() {
476: return lmodifiedVal;
477: }
478:
479: public void setLmodifiedVal(String lmodified) {
480: this .lmodifiedVal = lmodified;
481: }
482:
483: /*
484: */
485: public String getComments() {
486: return comments;
487: }
488:
489: public void setComments(String comments) {
490: this .comments = comments;
491: }
492:
493: /************************************************************
494: *
495: * Executes search.
496: *
497: ***********************************************************/
498: public void execute() {
499: QueryParser qp = null;
500: fromHit = (viewHits * (page - 1)) + 1;
501:
502: switch (searchType) {
503: case BASIC:
504: search = new Search(scope, viewAttributes, viewOrder,
505: fromHit, viewHits, queryLanguage, null, rdmServer);
506: break;
507: case ADVANCED:
508: qp = new QueryParser();
509: qp.setQueryParams(wordsOp, wordsVal, nowords, authorOp,
510: authorVal, titleOp, titleVal, urlOp, urlVal,
511: expiresOp, expiresVal, lmodifiedOp, lmodifiedVal,
512: comments);
513: scope = qp.getScope();
514: search = new Search(scope, viewAttributes, viewOrder,
515: fromHit, viewHits, queryLanguage, null, rdmServer);
516: break;
517: case CATEGORY:
518: search = new Search(browseCategory, viewAttributes,
519: viewOrder, fromHit, viewHits, queryLanguage, null,
520: rdmServer);
521: break;
522: case BROWSE:
523: search = new Search(browseCategory, viewAttributes,
524: viewOrder, fromHit, viewHits, queryLanguage, null,
525: rdmServer);
526: break;
527: default:
528: search = new Search(scope, rdmServer);
529: }
530:
531: search.setRDMType(rdmType);
532: search.doQuery(fromHit, viewHits);
533: if (search.getSOIFResult() == null) {
534: } else {
535: searchString = searchType + " " + search.toString();
536: soifResults = search.getSOIFResult();
537: soifString = soifResults.toStringList();
538:
539: debugLogger.log(Level.FINER, "PSSH_CSPS0001", searchString);
540: debugLogger.log(Level.FINER, "PSSH_CSPS0002", soifString);
541:
542: /* Debug
543: */
544: }
545:
546: totalCount = search.getHitCount();
547: resultCount = search.getResultCount();
548: totalPages = totalCount / viewHits + 1;
549: }
550:
551: /*
552: * @return value of SOIF being returned
553: */
554: public SOIF getSoifResults() {
555: return soifResults;
556: }
557:
558: /*
559: * @return total matches that match the search
560: */
561: public int getTotalCount() {
562: return totalCount;
563: }
564:
565: /*
566: * @return total pages that the search
567: * could display.
568: */
569: public int getTotalPages() {
570: return totalPages;
571: }
572:
573: /*
574: * @returns true if next page exists else false
575: */
576: public boolean next() {
577: if (page < totalPages)
578: next = true;
579: return next;
580: }
581:
582: /*
583: * @returns true if previous page exists else false
584: */
585: public boolean previous() {
586: if (page > 1)
587: previous = true;
588: return previous;
589: }
590:
591: /*
592: * @returns true if no matches were found
593: */
594: public boolean isNoHits() {
595: if (totalCount <= 0)
596: return true;
597:
598: return false;
599: }
600:
601: /*
602: * TODO: Remove this method.
603: * The message can be handled internally
604: */
605: public boolean isMoreThanOne() {
606: if (totalCount > 1) {
607: moreThanOne = true;
608: }
609:
610: return moreThanOne;
611: }
612:
613: public int getNextPage() {
614: nextPage = page + 1;
615: return nextPage;
616: }
617:
618: public int getPreviousPage() {
619: previousPage = page - 1;
620: return previousPage;
621: }
622:
623: /*
624: * For checking category matches
625: */
626: public boolean isMoreHits() {
627: if (resultCount < totalCount)
628: moreHits = true;
629: return moreHits;
630: }
631:
632: /*
633: * TODO: Remove these from the bean. HTML static text fields
634: * Ideally these messages should come from resource bundles
635: */
636: public String getHiddenMessage() {
637: hiddenMessage = "<input type=hidden name=page value= \"" + page
638: + "\">";
639: return hiddenMessage;
640: }
641:
642: /*
643: * Message used as header for display of search results
644: */
645: public String getMatchesFoundMsg() {
646: // Remove hardcoded message
647: // Get the message from a resource Bundle for i18n support
648: if (isMoreThanOne()) {
649: matchesFoundMsg = " Found " + totalCount
650: + " documents out of " + search.getDocumentCount()
651: + " total documents. Showing hits " + fromHit
652: + " to " + (fromHit + resultCount - 1) + ".";
653: } else {
654: matchesFoundMsg = " Found " + totalCount
655: + " document out of " + search.getDocumentCount()
656: + " total documents.";
657: }
658: return matchesFoundMsg;
659: }
660:
661: public String getNoMatchesFoundMsg() {
662: noMatchesFoundMsg = "No Document matches found";
663: return noMatchesFoundMsg;
664: }
665:
666: public String getCategoryMatchesFoundMsg() {
667: if (isMoreThanOne()) {
668: categoryMatchesFoundMsg = totalCount
669: + " category matches found.";
670: } else {
671: categoryMatchesFoundMsg = totalCount + " category match"
672: + " found, showing first "
673: + (fromHit + resultCount - 1) + ".";
674: }
675: return categoryMatchesFoundMsg;
676: }
677:
678: public String getNoCategoryMatchesFoundMsg() {
679: noCategoryMatchesFoundMsg = "No category matches found";
680: return noCategoryMatchesFoundMsg;
681: }
682:
683: /******************************************************************
684: * To be used for debugging
685: ******************************************************************/
686: public String getSoifString() {
687: return soifString;
688: }
689:
690: /* Debug method */
691: public String getSearchString() {
692: searchString = search.toString();
693: return searchString;
694: }
695:
696: }
|