views:

342

answers:

2

I am using Lucene.Net for indexing and searching documents, and I am using the following code to create or open an index if one exists:

 IndexWriter  writer = new IndexWriter(@"C:\index", new StandardAnalyzer(), !IndexExists);

    private  bool IndexExists
    {
        get
        {
            return ??
        }
    }

now how can implement IndexExists in a simple way? I don't need any exceptions to be thrown!

+4  A: 

The static method IndexReader.IndexExists(string path) (or one of its overloads) seems pretty suitable.

Marcus
+1  A: 

You could just use the constructor that doesn't take a boolean param. That will open an existing index if there is one there or create a new one if it doesn't exist.

Java documentation link (same for Lucene.Net): http://lucene.apache.org/java/2_3_1/api/org/apache/lucene/index/IndexWriter.html#IndexWriter(org.apache.lucene.store.Directory, org.apache.lucene.analysis.Analyzer)

Sean Carpenter
Lucene.net does not have this overload.
Marek
Which version of Lucene.Net is missing the overload? It's there in 2.4.
Sean Carpenter