Is it possible to combine indexes Lucene.NET

I have a number of Lucene.NET indexes created for archive files.
Indexes are created the same way. Indexes do not change, but each index takes several days. I want a single application to query all indexes.

I am wondering if it is possible to combine these indices into one index?

I know that an alternative approach would be to create a search application that queries each index in turn, but this is not my preferred option, since it introduces a lot of overhead for maintenance due to reasons that I cannot explain here.

+4
source share
1 answer

, @DarkFalcon, .Net, . . , . Java Lucene 4.5.0, , Lucene.Net.

API IndexWriter. IndexWriter.AddIndexes. , , , .


, , MultiReader , .


IndexMergeTool, :

using System;
using Lucene.Net.Index;
using Lucene.Net.Store;

public class IndexMergeTool
{
    public static void Main(string[] args)
    {
        if (args.Length < 3)
        {
            Console.Error.WriteLine("Usage: IndexMergeTool <mergedIndex> <index1> <index2> [index3] ...");
            Environment.Exit(1);
        }
        FSDirectory mergedIndex = FSDirectory.Open(args[0]);

        IndexWriter writer = new IndexWriter(mergedIndex, null, true, IndexWriter.MaxFieldLength.UNLIMITED);

        IndexReader[] indexes = new IndexReader[args.Length - 1];
        for (int i = 1; i < args.Length; i++)
        {
            indexes[i - 1] = IndexReader.Open(FSDirectory.Open(args[i]), true);
        }

        Console.WriteLine("Merging...");
        writer.AddIndexes(indexes);

        Console.WriteLine("Closing Readers...");
        foreach (IndexReader index in indexes)
        {
            index.Dispose();
        }
        writer.Dispose();
        Console.WriteLine("Done.");
    }
}
+1

Source: https://habr.com/ru/post/1620789/


All Articles