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.
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.
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.
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.
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.
The static method IndexReader.IndexExists(string path) (or one of its overloads) seems pretty suitable.
In < 4.0 is IndexReader.indexExists(org.apache.lucene.store.Directory)
In > 4.0 is DirectoryReader.indexExists(org.apache.lucene.store.Directory)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With