KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > search > component > UISearcher


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.faces.search.component;
6
7 import java.util.* ;
8 import javax.faces.component.UIComponent ;
9 import org.apache.lucene.document.Document;
10 import org.exoplatform.faces.core.component.UIExoComponentBase;
11 import org.exoplatform.faces.core.component.model.SelectItem;
12 import org.exoplatform.faces.search.component.model.DocumentDataHandler;
13 import org.exoplatform.services.indexing.*;
14 /**
15  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
16  * @since Aug 27, 2004
17  * @version $Id: UISearcher.java,v 1.2 2004/10/30 02:29:51 tuan08 Exp $
18  */

19 abstract public class UISearcher extends UIExoComponentBase {
20   final static public String JavaDoc SEARCH_SUMMARY_COMPONENT = "UISearchSummary" ;
21   
22   public UISearcher() throws Exception JavaDoc {
23   }
24   
25   public UISearcher(IndexingService service) throws Exception JavaDoc {
26     init(service) ;
27   }
28   
29   protected void init(IndexingService service) throws Exception JavaDoc {
30     setId("UISearcher") ;
31     setRendererType("ChildrenRenderer") ;
32     List children = getChildren() ;
33     UIComponent uiSearchBar = customizeUISearchBar(service) ;
34     children.add(uiSearchBar) ;
35     UIComponent uiSearchSummary = customizeUISearchSummary(service) ;
36     children.add(uiSearchSummary) ;
37     UIComponent uiViewDocument = customizeUIViewDocument(service) ;
38     uiViewDocument.setRendered(false) ;
39     children.add(uiViewDocument) ;
40     UIComponent uiASearch = customizeUIAdvancedSearch(service) ;
41     uiASearch.setRendered(false) ;
42     children.add(uiASearch) ;
43   }
44   
45   protected UIComponent customizeUISearchBar(IndexingService service) throws Exception JavaDoc {
46     List options = new ArrayList() ;
47     options.add(new SelectItem("#{UISearchBar.label.search-all}", ""));
48     options.add(new SelectItem("#{UISearchBar.label.search-title}",IndexingService.TITLE_FIELD));
49     options.add(new SelectItem("#{UISearchBar.label.search-desc}",IndexingService.DESCRIPTION_FIELD));
50     options.add(new SelectItem("#{UISearchBar.label.search-document}",IndexingService.DOCUMENT_FIELD));
51     options.add(new SelectItem("#{UISearchBar.label.search-author}",IndexingService.AUTHOR_FIELD));
52     UISearchBar uiBar = new UISearchBar();
53     uiBar.setSearchOptions(options) ;
54     return uiBar ;
55   }
56   
57   protected UIComponent customizeUIAdvancedSearch(IndexingService service) throws Exception JavaDoc {
58     return new UIAdvancedSearch(service);
59   }
60   
61   protected UIComponent customizeUISearchSummary(IndexingService service) throws Exception JavaDoc {
62     return new UISearchSummary(new DocumentDataHandler()) ;
63   }
64   
65   protected UIComponent customizeUIViewDocument(IndexingService service) throws Exception JavaDoc {
66     return new UIViewDocument(service);
67   }
68   
69   public Searcher getSearcher() throws Exception JavaDoc {
70     return null ;
71   }
72   
73   public void showAdvancedSearch() throws Exception JavaDoc {
74     setRenderedComponent(UIAdvancedSearch.class) ;
75   }
76   
77   public void quickSearch(String JavaDoc term, List fields) throws Exception JavaDoc {
78     MultipleFieldSearchInput searchInput = new MultipleFieldSearchInput(fields) ;
79     searchInput.setTerm(term) ;
80     Searcher searcher = getSearcher() ;
81     HitPageList result = searcher.search(searchInput) ;
82     UISearchSummary uiSummary =
83       (UISearchSummary)this.getChildComponentOfType(UISearchSummary.class) ;
84     uiSummary.setSearchResult(result) ;
85     setRenderedComponent(UISearchSummary.class) ;
86   }
87   
88   public void advancedSearch(List searchInputs, List searchModules) throws Exception JavaDoc {
89     Searcher searcher = getSearcher() ;
90     HitPageList result = searcher.search(searchInputs, searchModules) ;
91     UISearchSummary uiSummary =
92       (UISearchSummary)this.getChildComponentOfType(UISearchSummary.class) ;
93     uiSummary.setSearchResult(result) ;
94     setRenderedComponent(UISearchSummary.class) ;
95   }
96   
97   public void viewDocument(Document doc) throws Exception JavaDoc {
98     UIViewDocument uiViewDocument =
99       (UIViewDocument)this.getChildComponentOfType(UIViewDocument.class) ;
100     uiViewDocument.setDocument(doc) ;
101     setRenderedComponent(UIViewDocument.class) ;
102   }
103 }
Popular Tags