1 package org.nextime.ion.backoffice.action.search; 2 3 import java.io.IOException ; 4 import java.util.Vector ; 5 6 import javax.servlet.ServletException ; 7 import javax.servlet.http.HttpServletRequest ; 8 import javax.servlet.http.HttpServletResponse ; 9 10 import org.apache.struts.action.ActionError; 11 import org.apache.struts.action.ActionErrors; 12 import org.apache.struts.action.ActionForm; 13 import org.apache.struts.action.ActionForward; 14 import org.apache.struts.action.ActionMapping; 15 import org.nextime.ion.backoffice.action.BaseAction; 16 import org.nextime.ion.framework.config.Config; 17 import org.nextime.ion.framework.helper.Searcher; 18 import org.nextime.ion.framework.mapping.Mapping; 19 20 public class SearchAction extends BaseAction { 21 22 public ActionForward perform( 23 ActionMapping mapping, 24 ActionForm form, 25 HttpServletRequest request, 26 HttpServletResponse response) 27 throws IOException , ServletException { 28 29 checkUser(request); 31 32 String keyWords = request.getParameter("keyWords"); 34 35 request.setAttribute( "indexs", Config.getInstance().getIndexNames() ); 37 38 if (keyWords != null) { 39 if (!keyWords.trim().equals("")) { 40 try { 41 Mapping.begin(); 42 Vector result = Searcher.search(keyWords, request.getParameter("index")); 43 if( result.size()>0 ) { 44 request.setAttribute("result", result); 45 } 46 Mapping.rollback(); 47 } catch (Exception e) { 48 Mapping.rollback(); 49 throw new ServletException (e); 50 } 51 } else { 52 ActionErrors errors = new ActionErrors(); 53 ActionError error = new ActionError("error.search.noKeyWords"); 54 errors.add("keys",error); 55 request.setAttribute(ERROR_KEY,errors); 56 } 57 } 58 59 return (mapping.findForward("view")); 61 } 62 63 } 64 | Popular Tags |