日期:2014-05-17 浏览次数:20651 次
/** * * 创建搜索引擎 生成索引文件 * @param path 索引文件路径 */ @SuppressWarnings("unchecked") public boolean writerinNet(String path) { boolean flag = false; //对诉求表进行查寻 List<Appeal> list = this.getSqlMapClientTemplate().queryForList("appeal.writerinNet"); try { //生成索引文件的对象 作用是把一个Document对象加载到索引中来 IndexWriter iwriter = new IndexWriter(createFolder(path), analyzer, true); //索引文件生成的最大值 iwriter.setMaxFieldLength(25000); for(Appeal a:list){ Document doc = new Document(); doc.add(new Field("appealId", a.getAppealId()+"" , Field.Store.YES, Field.Index.TOKENIZED)); doc.add(new Field("appealTitle", a.getAppealTitle(), Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS)); doc.add(new Field("appealContent", a.getAppealContent(), Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS)); iwriter.addDocument(doc); } iwriter.close(); flag = true; } catch (Exception e) { System.out.println(e); } return flag; }