KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > factories > SearchResultFactory


1
2 package com.dotmarketing.factories;
3 import java.util.HashSet JavaDoc;
4 import java.util.LinkedHashSet JavaDoc;
5
6 import com.bitmechanic.spindle.ListDesc;
7 import com.dotmarketing.beans.SearchResult;
8 import com.dotmarketing.util.Config;
9 import com.dotmarketing.util.Logger;
10
11 /**
12  *
13  * @author rocco
14  */

15 public class SearchResultFactory {
16     
17     /** Creates a new instance of SearchResultFactory */
18     public SearchResultFactory() {
19     }
20     
21     public static HashSet JavaDoc getSearchResults(String JavaDoc keyword, String JavaDoc serverName) {
22         
23         java.util.ArrayList JavaDoc hits = new java.util.ArrayList JavaDoc();
24         ListDesc listDesc = new ListDesc();
25
26         Logger.debug(SearchResultFactory.class, "Running getSearchResults!!!");
27         HashSet JavaDoc SearchResults = new LinkedHashSet JavaDoc();
28         
29         try{
30             //hits = com.bitmechanic.spindle.Search.search(com.dotmarketing.util.Config.CONTEXT.getRealPath("/WEB-INF/spindle/" + serverName), keyword);
31
int maxResult = Config.getIntProperty("spindleMaxResult",10);
32             listDesc = com.bitmechanic.spindle.Search.search(com.dotmarketing.util.Config.CONTEXT.getRealPath("/WEB-INF/spindle/" + serverName), keyword,0,maxResult);
33             hits = listDesc.list;
34         }catch(Exception JavaDoc e){
35             Logger.error(SearchResultFactory.class, "Search Error: " + e, e);
36         }
37             
38         // These are the keys in the HashMap objects returned from the
39
// search.
40

41        
42         for (int i = 0; i < hits.size(); i++)
43         {
44             java.util.HashMap JavaDoc map = (java.util.HashMap JavaDoc)hits.get(i);
45
46             SearchResult searchResult = new SearchResult();
47             searchResult.setUrl(map.get("url").toString());
48             searchResult.setTitle(map.get("title").toString());
49             searchResult.setScore(map.get("score").toString());
50             searchResult.setDesc(map.get("desc").toString());
51
52             SearchResults.add(searchResult);
53             
54         }
55         return SearchResults;
56     }
57 }
58
Popular Tags