Lucene索引合并

版权声明:本文为博主原创文章,未经博主允许禁止转载(http://blog.csdn.net/napoay) https://blog.csdn.net/napoay/article/details/82019120
    @Test
    public void mergeIndex() throws IOException {
        Analyzer analyzer=new HanLPAnalyzer();
        IndexWriterConfig icw = new IndexWriterConfig(analyzer);
        icw.setOpenMode(IndexWriterConfig.OpenMode.APPEND);


        String indexPath1="/Users/pan/Documents/indices1";
        String indexPath2="/Users/pan/Documents/indices2";

        Directory dir1=FSDirectory.open(Paths.get(new File(indexPath1).toURI()));
        IndexWriter indexWriter1=new IndexWriter(dir1,icw);

        FSDirectory dir2=FSDirectory.open(Paths.get(new File(indexPath2).toURI()));
        FSDirectory[] fsDirectories={dir2};

        indexWriter1.addIndexes(fsDirectories);
        indexWriter1.close();
    }

猜你喜欢

转载自blog.csdn.net/napoay/article/details/82019120
今日推荐