user3685285
user3685285

Reputation: 6586

Lucene IndexWriter AlreadySet Exception

I am trying to create an IndexWriter and write to a Lucene Index. Here is my code:

public class Indexer {

    public static Analyzer _analyzer = new StandardAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48);

    private void WriteToIndex() {
        var config = new IndexWriterConfig(Lucene.Net.Util.LuceneVersion.LUCENE_48, _analyzer).SetUseCompoundFile(false);
        using (IndexWriter indexWriter = new IndexWriter(LuceneDirectory, config)) <-- This throws an error!
        {
            // ....
        }
    }

}

But I keep getting an exception when trying to create the IndexWriter:

Exception thrown: 'Lucene.Net.Util.SetOnce`1.AlreadySetException' in Lucene.Net.dll

Additional information: The object cannot be set twice!

What am I doing wrong? The code compiles perfectly. I'm using Lucene.NET, but I'm guessing it should apply to Java too.

Upvotes: 1

Views: 552

Answers (1)

femtoRgon
femtoRgon

Reputation: 33341

You are getting this exception because you are reusing an IndexWriterConfig, which is not intended to be shared between IndexWriter instances. Generate a new IndexWriterConfig instead, and it should work fine.

Upvotes: 3

Related Questions