01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.responders.search;
04:
05: import fitnesse.components.Searcher;
06:
07: public class SearchResponder extends ResultResponder {
08: private Searcher searcher;
09:
10: private String getSearchString() {
11: String searchString = (String) request.getInput("searchString");
12: return searchString;
13: }
14:
15: private String getSearchType() {
16: String searchType = (String) request.getInput("searchType");
17: searchType = searchType.toLowerCase();
18: if (searchType.indexOf("title") != -1)
19: return "Title";
20: else
21: return "Content";
22: }
23:
24: protected String getPageFooterInfo(int hits) throws Exception {
25: return "Found " + hits + " results for your search.";
26: }
27:
28: protected String getTitle() throws Exception {
29: return getSearchType() + " Search Results for '"
30: + getSearchString() + "'";
31: }
32:
33: protected void startSearching() throws Exception {
34: String searchString = getSearchString();
35: loadSearcher(searchString);
36: String searchType = getSearchType();
37: if ("Title".equals(searchType))
38: searcher.searchTitles(this );
39: else
40: searcher.searchContent(this );
41: }
42:
43: protected boolean shouldRespondWith404() {
44: return false;
45: }
46:
47: public void setSearcher(Searcher searcher) {
48: this .searcher = searcher;
49: }
50:
51: private void loadSearcher(String searchString) throws Exception {
52: if (searcher == null)
53: searcher = new Searcher(searchString, root);
54: }
55: }
|