/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

  1. /**
  2. * $RCSfile: CreateResultTask.java
  3. * $Revision: 1.0
  4. * $Date: Jan 30, 2011
  5. *
  6. * Copyright (C) 2010 SlFile, Inc. All rights reserved.
  7. *
  8. * This software is the proprietary information of SlFile, Inc.
  9. * Use is subject to license terms.
  10. */
  11. package com.searcherlocal.thread.result;
  12. import java.io.File;
  13. import java.sql.Connection;
  14. import java.util.Iterator;
  15. import java.util.List;
  16. import com.searchlocal.bean.ResultBean;
  17. import com.searchlocal.constants.Constant;
  18. import com.searchlocal.dao.BaseDao;
  19. import com.searchlocal.lucene.ContentSearcher;
  20. import com.searchlocal.param.CreateNewParam;
  21. import com.searchlocal.param.SearchParam;
  22. import com.searchlocal.service.ResultService;
  23. import com.searchlocal.thread.base.CRunnable;
  24. import com.searchlocal.util.KeyWordUtil;
  25. import com.searchlocal.util.XMLConfig;
  26. /**
  27. * ????????
  28. *
  29. * <p>Title: ????????</p>
  30. * <p>Description: </p>
  31. * <p>site: www.slfile.net</p>
  32. * @author changsong:qianjinfu@gmail.com
  33. * @version 1.0
  34. */
  35. public class CreateResultTask extends CRunnable {
  36. /** DB?? */
  37. private static Connection conn = null;
  38. /**
  39. * ??
  40. */
  41. public void excute() {
  42. // ?????
  43. String keyWordPath = Constant.path + "com\\searchlocal\\properties\\keyWord.properties";
  44. File keyWordFile = new File(keyWordPath);
  45. // ??????????,?????????
  46. if(keyWordFile.exists()){
  47. // ????????
  48. ResultService resultService = new ResultService();
  49. // ???????
  50. try {
  51. if(null == conn){
  52. conn = BaseDao.getConn(Constant.CommonInfo.DATABASE);
  53. }
  54. // ????id
  55. String keyWord = KeyWordUtil.getMsgbyId("keyword");
  56. String id = KeyWordUtil.getMsgbyId("id");
  57. // ???
  58. String database = Constant.CommonInfo.SEARCHER + id;
  59. // ??XML??
  60. XMLConfig xmler = new XMLConfig();
  61. List<CreateNewParam> entityList = xmler.getEntityList();
  62. // ??SearchParam
  63. SearchParam searchParam = new SearchParam();
  64. for (Iterator<CreateNewParam> iter = entityList.iterator(); iter.hasNext();) {
  65. CreateNewParam element = (CreateNewParam) iter.next();
  66. String searchName = element.getSearchname();
  67. if(searchName.equals(database)){
  68. searchParam.setIndexPath(element.getIndexpath());
  69. searchParam.setKeyWord(keyWord);
  70. }
  71. }
  72. // ??????,???????
  73. searchParam.setStartRow(0);
  74. searchParam.setEndRow(15);
  75. List<ResultBean> resultList = ContentSearcher.query(searchParam);
  76. // ????????
  77. resultService.deleteResultRecord(conn, Constant.CommonInfo.DATABASE);
  78. resultService.insertResultRecord(conn, resultList, Constant.CommonInfo.DATABASE);
  79. resultList.clear();
  80. // ???????
  81. entityList.clear();
  82. KeyWordUtil.prop.clear();
  83. keyWordFile.delete();
  84. System.gc();
  85. } catch (Exception e) {
  86. e.printStackTrace();
  87. }
  88. }
  89. }
  90. /**
  91. */
  92. public void run() {
  93. while (true) {
  94. synchronized (this) {
  95. excute();
  96. }
  97. try {
  98. System.out.println("??????");
  99. sleep(1 * 500);
  100. } catch (InterruptedException e) {
  101. e.printStackTrace();
  102. }
  103. }
  104. }
  105. }