/filesearch/SearchLocalFile/src/com/searcherlocal/thread/result/CreateResultTask.java
http://filesearch.googlecode.com/ · Java · 111 lines · 69 code · 6 blank · 36 comment · 6 complexity · 8174f1094abff10ac3bedf85db28732b MD5 · raw file
- /**
- * $RCSfile: CreateResultTask.java
- * $Revision: 1.0
- * $Date: Jan 30, 2011
- *
- * Copyright (C) 2010 SlFile, Inc. All rights reserved.
- *
- * This software is the proprietary information of SlFile, Inc.
- * Use is subject to license terms.
- */
- package com.searcherlocal.thread.result;
-
- import java.io.File;
- import java.sql.Connection;
- import java.util.Iterator;
- import java.util.List;
-
- import com.searchlocal.bean.ResultBean;
- import com.searchlocal.constants.Constant;
- import com.searchlocal.dao.BaseDao;
- import com.searchlocal.lucene.ContentSearcher;
- import com.searchlocal.param.CreateNewParam;
- import com.searchlocal.param.SearchParam;
- import com.searchlocal.service.ResultService;
- import com.searchlocal.thread.base.CRunnable;
- import com.searchlocal.util.KeyWordUtil;
- import com.searchlocal.util.XMLConfig;
-
- /**
- * ????????
- *
- * <p>Title: ????????</p>
- * <p>Description: </p>
- * <p>site: www.slfile.net</p>
- * @author changsong:qianjinfu@gmail.com
- * @version 1.0
- */
- public class CreateResultTask extends CRunnable {
-
- /** DB?? */
- private static Connection conn = null;
-
- /**
- * ??
- */
- public void excute() {
- // ?????
- String keyWordPath = Constant.path + "com\\searchlocal\\properties\\keyWord.properties";
- File keyWordFile = new File(keyWordPath);
- // ??????????,?????????
- if(keyWordFile.exists()){
- // ????????
- ResultService resultService = new ResultService();
- // ???????
- try {
- if(null == conn){
- conn = BaseDao.getConn(Constant.CommonInfo.DATABASE);
- }
- // ????id
- String keyWord = KeyWordUtil.getMsgbyId("keyword");
- String id = KeyWordUtil.getMsgbyId("id");
- // ???
- String database = Constant.CommonInfo.SEARCHER + id;
- // ??XML??
- XMLConfig xmler = new XMLConfig();
- List<CreateNewParam> entityList = xmler.getEntityList();
- // ??SearchParam
- SearchParam searchParam = new SearchParam();
- for (Iterator<CreateNewParam> iter = entityList.iterator(); iter.hasNext();) {
- CreateNewParam element = (CreateNewParam) iter.next();
- String searchName = element.getSearchname();
- if(searchName.equals(database)){
- searchParam.setIndexPath(element.getIndexpath());
- searchParam.setKeyWord(keyWord);
- }
- }
- // ??????,???????
- searchParam.setStartRow(0);
- searchParam.setEndRow(15);
- List<ResultBean> resultList = ContentSearcher.query(searchParam);
- // ????????
- resultService.deleteResultRecord(conn, Constant.CommonInfo.DATABASE);
- resultService.insertResultRecord(conn, resultList, Constant.CommonInfo.DATABASE);
- resultList.clear();
- // ???????
- entityList.clear();
- KeyWordUtil.prop.clear();
- keyWordFile.delete();
- System.gc();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- /**
- */
- public void run() {
- while (true) {
- synchronized (this) {
- excute();
- }
- try {
- System.out.println("??????");
- sleep(1 * 500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }