1 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 19 abstract public class UISearcher extends UIExoComponentBase { 20 final static public String SEARCH_SUMMARY_COMPONENT = "UISearchSummary" ; 21 22 public UISearcher() throws Exception { 23 } 24 25 public UISearcher(IndexingService service) throws Exception { 26 init(service) ; 27 } 28 29 protected void init(IndexingService service) throws Exception { 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 { 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 { 58 return new UIAdvancedSearch(service); 59 } 60 61 protected UIComponent customizeUISearchSummary(IndexingService service) throws Exception { 62 return new UISearchSummary(new DocumentDataHandler()) ; 63 } 64 65 protected UIComponent customizeUIViewDocument(IndexingService service) throws Exception { 66 return new UIViewDocument(service); 67 } 68 69 public Searcher getSearcher() throws Exception { 70 return null ; 71 } 72 73 public void showAdvancedSearch() throws Exception { 74 setRenderedComponent(UIAdvancedSearch.class) ; 75 } 76 77 public void quickSearch(String term, List fields) throws Exception { 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 { 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 { 98 UIViewDocument uiViewDocument = 99 (UIViewDocument)this.getChildComponentOfType(UIViewDocument.class) ; 100 uiViewDocument.setDocument(doc) ; 101 setRenderedComponent(UIViewDocument.class) ; 102 } 103 } | Popular Tags |