lucene4.1如何进行段合并

tianpeng91 发布于 2013/02/22 09:21
阅读 974
收藏 0
请问lucene4.1如何进行段合并呢?在3.0的版本有一个 optimize()方法,4.1的API改了比较多,郁闷啊,没找到咋弄
加载中
0
XzhiF
XzhiF
forceMeger方法, 3.5去掉了optimize()方法,改名为forceMeger
tianpeng91
tianpeng91
非常感谢,我去用MergePolicy整了半天愣是没搞出来
0
dedenj
dedenj
我想知道。。   optimize  的链接是OSC自动生成的吗。。
tianpeng91
tianpeng91
不是,是我复制过来的,哥,,,我以为你回答我问题的啊,,,,
0
loking
loking
public synchronized static void createIndexs() {
		Directory dir = null;
		IndexWriter iw = null;
		IndexWriterConfig iwc = null;
		Document doc = null;
		List<Post> list = null;

		IndexWriter iwRam = null;
		RAMDirectory ramDir = null;
		try {
			list = ResultDAO.getPostList();
			dir = LuceneCommon.getFSDirectory();
			ramDir = LuceneCommon.getRAMDirectory();
			iwc = new IndexWriterConfig(Version.LUCENE_40, LuceneCommon
					.getAnalyzer());
			iwc.setOpenMode(OpenMode.CREATE);
			iw = new IndexWriter(dir, iwc);
			iwRam = new IndexWriter(ramDir, iwc);
			for (int i = 0; i < list.size(); i++) {
				doc = new Document();
				Field id = new TextField("id", list.get(i).getId(),
						Store.YES);
				Field title = new TextField("title", list.get(i).getTitle(),
						Store.YES);
				Field content = new TextField("content", list.get(i).getContent(),
						Store.YES);
				Field laiyuan = new TextField("laiyuan", list.get(i).getLaiyuan(),
						Store.YES);
				title.setBoost(1f);
				doc.add(id);
				doc.add(title);
				doc.add(content);
				doc.add(laiyuan);
				iw.addDocument(doc);
				iwRam.addDocument(doc);
			}
			iwDocNum = iw.maxDoc();// 提交之前还是之后
			iw.close();
			iwRam.close();
			System.out.println("-------------------------------------");
			System.out.println("            " + iwDocNum);
			System.out.println("-------------------------------------");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				iw.close();
				dir.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
返回顶部
顶部