⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wareaction.java

📁 在SSH框架下用Lucene做的一个搜索引擎系统
💻 JAVA
字号:
package com.hapark.action;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.lucene.document.Document;
import org.apache.lucene.search.Hits;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.hapark.service.WareService;

public class WareAction extends DispatchAction{

	
	private WareService  wareService ;

	/**
	 * 创建索引
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward createIndex(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

		wareService.addIndex();

		return mapping.findForward("index") ;
	}

	
	
	/**
	 * 搜索索引
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
    public ActionForward searchIndex(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

    	String key = request.getParameter("key");
    	Hits hits = null ;
    	if(StringUtils.isBlank(key)){
    		request.setAttribute("hits", hits);
    		return mapping.findForward("index") ;
    		
    	}else{
    		Date startTime = new Date();
    		hits = wareService.searchIndex(key, "");

    		Date endTime = new Date();
    		request.setAttribute("hits", hits);
    		request.setAttribute("hitslength", hits.length());
    		request.setAttribute("usetime", endTime.getTime()-startTime.getTime());
    		return mapping.findForward("search") ;
    	}
	}


	public void setWareService(WareService wareService) {
		
		this.wareService = wareService;
	}
    
    
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -