Exemplo n.º 1
0
 internal static void InitialiseBlankIndex(Directory directory)
 {
     new IndexWriter(directory,
                     GetAnalyzer(),
                     true,
                     IndexWriter.MaxFieldLength.UNLIMITED).Dispose();
 }
Exemplo n.º 2
0
        internal static global::Lucene.Net.Index.IndexReader CreateLuceneReader(Directory directory, bool secondAttempt = false)
        {
            try
            {
                // Scan the index directory for segments files to check for corruption
                var files         = directory.ListAll();
                var foundSegments = false;
                foreach (var file in files)
                {
                    if (file.StartsWith("segments", StringComparison.InvariantCultureIgnoreCase))
                    {
                        foundSegments = true;
                        break;
                    }
                }
                if (!foundSegments)
                {
                    foreach (var file in files)
                    {
                        directory.DeleteFile(file);
                    }
                }

                var reader = global::Lucene.Net.Index.IndexReader.Open(directory, true);
                return(reader);
            }
            catch (FileNotFoundException fnf)
            {
                InitialiseBlankIndex(directory);
                if (!secondAttempt)
                {
                    return(CreateLuceneReader(directory, true));
                }
                throw new InvalidOperationException("Could not create an index reader - tried twice", fnf);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Could not create an index reader", ex);
            }
        }
Exemplo n.º 3
0
 internal static IndexWriter CreateLuceneWriter(StandardAnalyzer standardAnalyzer, Directory directory)
 {
     return(new IndexWriter(directory,
                            standardAnalyzer,
                            false,
                            IndexWriter.MaxFieldLength.UNLIMITED));
 }
Exemplo n.º 4
0
        internal static global::Lucene.Net.Index.IndexReader CreateLuceneReader(Directory directory, bool secondAttempt = false)
        {
            try
            {
                // Scan the index directory for segments files to check for corruption
                var files = directory.ListAll();
                var foundSegments = false;
                foreach (var file in files)
                {
                    if (file.StartsWith("segments", StringComparison.InvariantCultureIgnoreCase))
                    {
                        foundSegments = true;
                        break;
                    }
                }
                if (!foundSegments)
                {
                    foreach (var file in files)
                    {
                        directory.DeleteFile(file);
                    }
                }

                var reader = global::Lucene.Net.Index.IndexReader.Open(directory, true);
                return reader;
            }
            catch (FileNotFoundException fnf)
            {
                InitialiseBlankIndex(directory);
                if (!secondAttempt) return CreateLuceneReader(directory, true);
                throw new InvalidOperationException("Could not create an index reader - tried twice", fnf);
            }
            catch(Exception ex)
            {
                throw new InvalidOperationException("Could not create an index reader", ex);
            }
        }
Exemplo n.º 5
0
 internal static IndexWriter CreateLuceneWriter(StandardAnalyzer standardAnalyzer, Directory directory)
 {
     return new IndexWriter(directory,
                            standardAnalyzer,
                            false,
                            IndexWriter.MaxFieldLength.UNLIMITED);
 }
Exemplo n.º 6
0
 internal static void InitialiseBlankIndex(Directory directory)
 {
     new IndexWriter(directory,
                     GetAnalyzer(),
                     true,
                     IndexWriter.MaxFieldLength.UNLIMITED).Dispose();
 }