Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to identify if a Lucene.Net Index exists in a folder?

Tags:

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.

like image 664
Elias Haileselassie Avatar asked Jun 16 '09 14:06

Elias Haileselassie


People also ask

Where are Lucene indexes stored?

When using the default Sitefinity CMS search service (Lucene), the search index definition (configurations which content to be indexed) is stored in your website database, and the actual search index files – on the file system. By default, the search index files are in the ~/App_Data/Sitefinity/Search/ folder.

How do you search Lucene?

Lucene supports fielded data. When performing a search you can either specify a field, or use the default field. The field names and default field is implementation specific. You can search any field by typing the field name followed by a colon ":" and then the term you are looking for.

How does Lucene index search work?

Lucene is able to achieve fast search responses because, instead of searching the text directly, it searches an index instead. This would be the equivalent of retrieving pages in a book related to a keyword by searching the index at the back of a book, as opposed to searching the words in each page of the book.

What is a Lucene index?

A Lucene Index Is an Inverted IndexA term combines a field name with a token. The terms created from the non-text fields in the document are pairs consisting of the field name and the field value. The terms created from text fields are pairs of field name and token.


2 Answers

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

like image 80
Marcus Avatar answered Oct 16 '22 14:10

Marcus


In < 4.0 is IndexReader.indexExists(org.apache.lucene.store.Directory)

In > 4.0 is DirectoryReader.indexExists(org.apache.lucene.store.Directory)

like image 28
mad Avatar answered Oct 16 '22 16:10

mad