コード例 #1
0
        internal Lucene.Net.Store.Directory MakeRAMDirectoryPhysical(RAMDirectory ramDir, string indexName)
        {
            var newDir = new LuceneCodecDirectory(Path.Combine(path, MonoHttpUtility.UrlEncode(IndexDefinitionStorage.FixupIndexName(indexName, path))), documentDatabase.IndexCodecs.OfType <AbstractIndexCodec>());

            Lucene.Net.Store.Directory.Copy(ramDir, newDir, true);
            return(newDir);
        }
コード例 #2
0
        protected Lucene.Net.Store.Directory OpenOrCreateLuceneDirectory(
            IndexDefinition indexDefinition,
            string indexName     = null,
            bool createIfMissing = true)
        {
            Lucene.Net.Store.Directory directory;
            if (indexDefinition.IsTemp || configuration.RunInMemory)
            {
                directory = new RAMDirectory();
                new IndexWriter(directory, dummyAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED).Dispose();                 // creating index structure
            }
            else
            {
                var indexDirectory = indexName ?? IndexDefinitionStorage.FixupIndexName(indexDefinition.Name, path);
                var indexFullPath  = Path.Combine(path, MonoHttpUtility.UrlEncode(indexDirectory));
                directory = new LuceneCodecDirectory(indexFullPath, documentDatabase.IndexCodecs.OfType <AbstractIndexCodec>());

                if (!IndexReader.IndexExists(directory))
                {
                    if (createIfMissing == false)
                    {
                        throw new InvalidOperationException("Index does not exists: " + indexDirectory);
                    }

                    WriteIndexVersion(directory);

                    //creating index structure if we need to
                    new IndexWriter(directory, dummyAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED).Dispose();
                }
                else
                {
                    EnsureIndexVersionMatches(indexName, directory);
                    if (directory.FileExists("write.lock"))                    // force lock release, because it was still open when we shut down
                    {
                        IndexWriter.Unlock(directory);
                        // for some reason, just calling unlock doesn't remove this file
                        directory.DeleteFile("write.lock");
                    }
                    if (directory.FileExists("writing-to-index.lock"))                     // we had an unclean shutdown
                    {
                        if (configuration.ResetIndexOnUncleanShutdown)
                        {
                            throw new InvalidOperationException("Rude shutdown detected on: " + indexDirectory);
                        }

                        CheckIndexAndRecover(directory, indexDirectory);
                        directory.DeleteFile("writing-to-index.lock");
                    }
                }
            }

            return(directory);
        }
コード例 #3
0
        public void WithoutGettingErrors()
        {
            using(var luceneCodecDirectory = new LuceneCodecDirectory(Path, Enumerable.Empty<AbstractIndexCodec>()))
            using(var simpleAnalyzer = new SimpleAnalyzer())
            {
                using (var w = new IndexWriter(luceneCodecDirectory, simpleAnalyzer, true, IndexWriter.MaxFieldLength.UNLIMITED))
                {
                    var doc = new Lucene.Net.Documents.Document();
                    doc.Add(new Field("test", "value", Field.Store.YES, Field.Index.ANALYZED));
                    w.AddDocument(doc);
                }

                using(var s = new IndexSearcher(luceneCodecDirectory))
                {
                    var termQuery = new TermQuery(new Term("test", "value"));
                    var topDocs = s.Search(termQuery, 10);
                    Assert.Equal(1, topDocs.TotalHits);
                }
            }

        }
コード例 #4
0
ファイル: IndexStorage.cs プロジェクト: felipeleusin/ravendb
		internal Lucene.Net.Store.Directory MakeRAMDirectoryPhysical(RAMDirectory ramDir, IndexDefinition indexDefinition)
		{
			var newDir = new LuceneCodecDirectory(Path.Combine(path, indexDefinition.IndexId.ToString()), documentDatabase.IndexCodecs.OfType<AbstractIndexCodec>());
			Lucene.Net.Store.Directory.Copy(ramDir, newDir, false);
			return newDir;
		}
コード例 #5
0
ファイル: IndexStorage.cs プロジェクト: felipeleusin/ravendb
		protected Lucene.Net.Store.Directory OpenOrCreateLuceneDirectory(IndexDefinition indexDefinition, bool createIfMissing = true)
		{
			Lucene.Net.Store.Directory directory;
			if (configuration.RunInMemory ||
				(indexDefinition.IsMapReduce == false &&  // there is no point in creating map/reduce indexes in memory, we write the intermediate results to disk anyway
				 indexDefinitionStorage.IsNewThisSession(indexDefinition) &&
				 indexDefinition.DisableInMemoryIndexing == false &&
				 configuration.DisableInMemoryIndexing == false))
			{
				directory = new RAMDirectory();
				new IndexWriter(directory, dummyAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED).Dispose(); // creating index structure
			}
			else
			{
				var indexDirectory = indexDefinition.IndexId.ToString();
				var indexFullPath = Path.Combine(path, indexDirectory);
				directory = new LuceneCodecDirectory(indexFullPath, documentDatabase.IndexCodecs.OfType<AbstractIndexCodec>());

				if (!IndexReader.IndexExists(directory))
				{
					if (createIfMissing == false)
						throw new InvalidOperationException(string.Format("Index directory '{0}' does not exists for '{1}' index.", indexFullPath, indexDefinition.Name));

					WriteIndexVersion(directory, indexDefinition);

					//creating index structure if we need to
					new IndexWriter(directory, dummyAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED).Dispose();
				}
				else
				{
					EnsureIndexVersionMatches(directory, indexDefinition);
					if (directory.FileExists("write.lock"))// force lock release, because it was still open when we shut down
					{
						IndexWriter.Unlock(directory);
						// for some reason, just calling unlock doesn't remove this file
						directory.DeleteFile("write.lock");
					}
					if (directory.FileExists("writing-to-index.lock")) // we had an unclean shutdown
					{
						if (configuration.ResetIndexOnUncleanShutdown)
							throw new InvalidOperationException(string.Format("Rude shutdown detected on '{0}' index in '{1}' directory.", indexDefinition.Name, indexFullPath));

						CheckIndexAndTryToFix(directory, indexDefinition);
						directory.DeleteFile("writing-to-index.lock");
					}
				}
			}

			return directory;

		}
コード例 #6
0
ファイル: IndexStorage.cs プロジェクト: synhershko/ravendb
		internal Lucene.Net.Store.Directory MakeRAMDirectoryPhysical(RAMDirectory ramDir, string indexName)
		{
			var newDir = new LuceneCodecDirectory(Path.Combine(path, MonoHttpUtility.UrlEncode(IndexDefinitionStorage.FixupIndexName(indexName, path))), documentDatabase.IndexCodecs.OfType<AbstractIndexCodec>());
			Lucene.Net.Store.Directory.Copy(ramDir, newDir, true);
			return newDir;
		}
コード例 #7
0
ファイル: IndexStorage.cs プロジェクト: synhershko/ravendb
		protected Lucene.Net.Store.Directory OpenOrCreateLuceneDirectory(
			IndexDefinition indexDefinition,
			string indexName = null,
			bool createIfMissing = true)
		{
			Lucene.Net.Store.Directory directory;
			if (indexDefinition.IsTemp || configuration.RunInMemory)
			{
				directory = new RAMDirectory();
				new IndexWriter(directory, dummyAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED).Dispose(); // creating index structure
			}
			else
			{
				var indexDirectory = indexName ?? IndexDefinitionStorage.FixupIndexName(indexDefinition.Name, path);
				var indexFullPath = Path.Combine(path, MonoHttpUtility.UrlEncode(indexDirectory));
				directory = new LuceneCodecDirectory(indexFullPath, documentDatabase.IndexCodecs.OfType<AbstractIndexCodec>());

				if (!IndexReader.IndexExists(directory))
				{
					if (createIfMissing == false)
						throw new InvalidOperationException("Index does not exists: " + indexDirectory);

					WriteIndexVersion(directory);

					//creating index structure if we need to
					new IndexWriter(directory, dummyAnalyzer, IndexWriter.MaxFieldLength.UNLIMITED).Dispose();
				}
				else
				{
					EnsureIndexVersionMatches(indexName, directory);
					if (directory.FileExists("write.lock"))// force lock release, because it was still open when we shut down
					{
						IndexWriter.Unlock(directory);
						// for some reason, just calling unlock doesn't remove this file
						directory.DeleteFile("write.lock");
					} 
					if (directory.FileExists("writing-to-index.lock")) // we had an unclean shutdown
					{
						if (configuration.ResetIndexOnUncleanShutdown)
							throw new InvalidOperationException("Rude shutdown detected on: " + indexDirectory);

						CheckIndexAndRecover(directory, indexDirectory);
						directory.DeleteFile("writing-to-index.lock");
					}
				}
			}

			return directory;

		}
コード例 #8
0
ファイル: IndexStorage.cs プロジェクト: IdanHaim/ravendb
 internal LuceneDirectory MakeRAMDirectoryPhysical(RAMDirectory ramDir, string indexFolder)
 {
     var newDir = new LuceneCodecDirectory(indexFolder, new AbstractIndexCodec[0]);
     LuceneDirectory.Copy(ramDir, newDir, false);
     WriteIndexVersion(newDir);
     return newDir;
 }