PutIndex() public method

public PutIndex ( string name, Raven.Database.Indexing.IndexDefinition definition ) : string
name string
definition Raven.Database.Indexing.IndexDefinition
return string
Ejemplo n.º 1
0
		public QueryingOnStaleIndexes()
		{
			db = new DocumentDatabase(new RavenConfiguration { DataDirectory = "raven.db.test.esent", RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true });
			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
		

		}
Ejemplo n.º 2
0
		public void Execute(DocumentDatabase database)
		{
			Database = database;


			var indexDefinition = database.GetIndexDefinition(RavenDocumentsByExpirationDate);
			if (indexDefinition == null)
			{
				database.PutIndex(RavenDocumentsByExpirationDate,
								  new IndexDefinition
								  {
									  Map =
										  @"
	from doc in docs
	let expiry = doc[""@metadata""][""Raven-Expiration-Date""]
	where expiry != null
	select new { Expiry = expiry }
"
								  });
			}

			var deleteFrequencyInSeconds = database.Configuration.GetConfigurationValue<int>("Raven/Expiration/DeleteFrequencySeconds") ?? 300;
			logger.Info("Initialized expired document cleaner, will check for expired documents every {0} seconds",
						deleteFrequencyInSeconds);
			timer = new Timer(TimerCallback, null, TimeSpan.FromSeconds(deleteFrequencyInSeconds), TimeSpan.FromSeconds(deleteFrequencyInSeconds));

		}
Ejemplo n.º 3
0
        public void Execute(DocumentDatabase database)
        {
            if (!database.IsBundleActive("IndexedAttachments"))
                return;

            var index = new IndexDefinition
                        {
                            Map = @"from doc in docs
            where doc[""@metadata""][""Raven-Attachment-Key""] != null
            select new
            {
            AttachmentKey = doc[""@metadata""][""Raven-Attachment-Key""],
            Filename = doc[""@metadata""][""Raven-Attachment-Filename""],
            Text = doc.Text
            }",
                            TransformResults = @"from result in results
            select new
            {
            AttachmentKey = result[""@metadata""][""Raven-Attachment-Key""],
            Filename = result[""@metadata""][""Raven-Attachment-Filename""]
            }"
                        };

            // NOTE: The transform above is specifically there to keep the Text property
            //       from being returned.  The results could get very large otherwise.

            index.Indexes.Add("Text", FieldIndexing.Analyzed);
            index.Stores.Add("Text", FieldStorage.Yes);
            index.TermVectors.Add("Text", FieldTermVector.WithPositionsAndOffsets);

            database.PutIndex("Raven/Attachments", index);
        }
		public MapReduce_IndependentSteps()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true
			});
			db.PutIndex("CommentsCountPerBlog", new IndexDefinition{Map = map, Reduce = reduce, Indexes = {{"blog_id", FieldIndexing.NotAnalyzed}}});
		}
Ejemplo n.º 5
0
		public BackupRestore()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false
			});
			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
		}
Ejemplo n.º 6
0
 public MapReduce()
 {
     db = new DocumentDatabase(new RavenConfiguration
     {
         DataDirectory = "raven.db.test.esent",
         RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true
     });
     db.PutIndex("CommentsCountPerBlog", new IndexDefinition{Map = map, Reduce = reduce, Indexes = {{"blog_id", FieldIndexing.NotAnalyzed}}});
     db.SpinBackgroundWorkers();
 }
Ejemplo n.º 7
0
        public MapReduce()
        {
            db = new DocumentDatabase(new RavenConfiguration {DataDirectory = "raven.db.test.esent"});
            db.PutIndex("CommentsCountPerBlog", new IndexDefinition{Map = map, Reduce = reduce, Indexes = {{"blog_id", FieldIndexing.Untokenized}}});
            db.SpinBackgroundWorkers();

            BasicConfigurator.Configure(
                new OutputDebugStringAppender
                {
                    Layout = new SimpleLayout()
                });
        }
		public IncrementalBackupRestore()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = "raven.db.test.esent",
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false,
				Settings =
					{
						{"Raven/Esent/CircularLog", "false"}
					}
			});
			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
		}
Ejemplo n.º 9
0
		public void IncrementalBackupWithCircularLogThrows()
		{
			db.Dispose();
			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false,
			});

			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
		
			db.Put("ayende", null, RavenJObject.Parse("{'email':'*****@*****.**'}"), new RavenJObject(), null);

			Assert.Throws<InvalidOperationException>(() => db.StartBackup(BackupDir, true, new DatabaseDocument()));
		}
Ejemplo n.º 10
0
		public RavenDB_1007_incremental_backup()
		{
			IOExtensions.DeleteDirectory(BackupDir);

			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false,
				Settings =
					{
						{"Raven/Esent/CircularLog", "false"}
					}
			});
			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
		}
Ejemplo n.º 11
0
        public Statistics()
        {
            db = new DocumentDatabase(new RavenConfiguration {DataDirectory = "raven.db.test.esent"});
            db.SpinBackgroundWorkers();

            db.PutIndex("pagesByTitle2",
                        new IndexDefinition
                        {
                            Map = @"
                    from doc in docs
                    where doc.type == ""page""
                    select new {  f = 2 / doc.size };
                "
                        });
        }
Ejemplo n.º 12
0
		public Statistics()
		{
			store = NewDocumentStore();
			db = store.DocumentDatabase;

			db.PutIndex("pagesByTitle2",
						new IndexDefinition
						{
							Map = @"
					from doc in docs
					where doc.type == ""page""
					select new {  f = 2 / doc.size };
				"
						});
		}
Ejemplo n.º 13
0
        public Statistics()
        {
            db = new DocumentDatabase(new RavenConfiguration {DataDirectory = "raven.db.test.esent", RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true});
            db.SpinBackgroundWorkers();

            db.PutIndex("pagesByTitle2",
                        new IndexDefinition
                        {
                            Map = @"
                    from doc in docs
                    where doc.type == ""page""
                    select new {  f = 2 / doc.size };
                "
                        });
        }
Ejemplo n.º 14
0
		public ReadTriggers()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				RunInMemory = true,
				Container = new CompositionContainer(new TypeCatalog(
					typeof(VetoReadsOnCapitalNamesTrigger),
					typeof(HiddenDocumentsTrigger),
					typeof(UpperCaseNamesTrigger)))
			});
			db.PutIndex("ByName",
						new IndexDefinition
						{
							Map = "from doc in docs select new{ doc.name}"
						});
		}
Ejemplo n.º 15
0
		public ReadTriggers()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = "raven.db.test.esent",
				Container = new CompositionContainer(new TypeCatalog(
					typeof(VetoReadsOnCapitalNamesTrigger),
					typeof(HiddenDocumentsTrigger),
					typeof(UpperCaseNamesTrigger)))
			});
			db.SpinBackgroundWorkers();
			db.PutIndex("ByName",
			            new IndexDefinition
			            {
			            	Map = "from doc in docs select new{ doc.name}"
			            });
		}
        public static void CreateIndex(DocumentDatabase database)
        {
            var index = new IndexDefinition {
                                                Map = string.Format(
                                                    @"from doc in docs
            where doc[""{0}""][""{1}""] == ""{2}""
               && doc[""{0}""][""{3}""] == true
            select new
            {{
            {4} = doc[""{0}""][""{5}""],
            }}",
                                                    Constants.Metadata,
                                                    TemporalMetadata.RavenDocumentTemporalStatus, TemporalStatus.Revision,
                                                    TemporalMetadata.RavenDocumentTemporalPending,
                                                    Activation, TemporalMetadata.RavenDocumentTemporalEffectiveStart)
                                            };

            if (database.GetIndexDefinition(TemporalConstants.PendingRevisionsIndex) == null)
                database.PutIndex(TemporalConstants.PendingRevisionsIndex, index);
        }
Ejemplo n.º 17
0
		public QueryingOnDefaultIndex()
		{
			db = new DocumentDatabase(new RavenConfiguration {DataDirectory = DataDir, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true});
			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
			db.SpinBackgroundWorkers();
		}
Ejemplo n.º 18
0
		public IndexingBehavior()
		{
			store = NewDocumentStore();
			db = store.DocumentDatabase;
			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
		}
Ejemplo n.º 19
0
		public void AfterFailedRestoreOfIndex_ShouldGenerateWarningAndResetIt()
		{
			using (var db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false,
			}))
			{
				db.SpinBackgroundWorkers();
				db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());

				db.Put("users/1", null, RavenJObject.Parse("{'Name':'Arek'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);
				db.Put("users/2", null, RavenJObject.Parse("{'Name':'David'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);
				db.Put("users/3", null, RavenJObject.Parse("{'Name':'Daniel'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);

				WaitForIndexing(db);

				db.StartBackup(BackupDir, false, new DatabaseDocument());
				WaitForBackup(db, true);
			}
			IOExtensions.DeleteDirectory(DataDir);

			// lock file to simulate IOException when restore operation will try to copy this file
			using (var file = File.Open(Path.Combine(BackupDir, "Indexes\\Raven%2fDocumentsByEntityName\\segments.gen"),
				                     FileMode.Open, FileAccess.ReadWrite, FileShare.None))
			{
				var sb = new StringBuilder();

				DocumentDatabase.Restore(new RavenConfiguration(), BackupDir, DataDir, s => sb.Append(s), defrag: true);

				Assert.Contains(
					"Error: Index Raven%2fDocumentsByEntityName could not be restored. All already copied index files was deleted." +
					" Index will be recreated after launching Raven instance",
					sb.ToString());
			}

			using (var db = new DocumentDatabase(new RavenConfiguration {DataDirectory = DataDir}))
			{
				db.SpinBackgroundWorkers();
				QueryResult queryResult;
				do
				{
					queryResult = db.Query("Raven/DocumentsByEntityName", new IndexQuery
					{
						Query = "Tag:[[Users]]",
						PageSize = 10
					}, CancellationToken.None);
				} while (queryResult.IsStale);
				Assert.Equal(3, queryResult.Results.Count);
			}
		}
Ejemplo n.º 20
0
		public void AfterFailedRestoreOfIndex_ShouldGenerateWarningAndResetIt()
		{
			using (var db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false,
				Settings =
				{
					{"Raven/Esent/CircularLog", "false"}
				}
			}))
			{
				db.SpinBackgroundWorkers();
				db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());

				db.Put("users/1", null, RavenJObject.Parse("{'Name':'Arek'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);
				db.Put("users/2", null, RavenJObject.Parse("{'Name':'David'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);

				WaitForIndexing(db);

				db.StartBackup(BackupDir, false, new DatabaseDocument());
				WaitForBackup(db, true);

				db.Put("users/3", null, RavenJObject.Parse("{'Name':'Daniel'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);

				WaitForIndexing(db);

				db.StartBackup(BackupDir, true, new DatabaseDocument());
				WaitForBackup(db, true);

			}
			IOExtensions.DeleteDirectory(DataDir);

			var incrementalDirectories = Directory.GetDirectories(BackupDir, "Inc*");

			// delete 'index-files.required-for-index-restore' to make backup corrupted according to the reported error
			File.Delete(Path.Combine(incrementalDirectories.First(),
			                         "Indexes\\Raven%2fDocumentsByEntityName\\index-files.required-for-index-restore"));

			var sb = new StringBuilder();

			DocumentDatabase.Restore(new RavenConfiguration(), BackupDir, DataDir, s => sb.Append(s), defrag: true);

			Assert.Contains(
				"Error: Index Raven%2fDocumentsByEntityName could not be restored. All already copied index files was deleted." +
				" Index will be recreated after launching Raven instance",
				sb.ToString());

			using (var db = new DocumentDatabase(new RavenConfiguration {DataDirectory = DataDir}))
			{
				db.SpinBackgroundWorkers();
				QueryResult queryResult;
				do
				{
					queryResult = db.Query("Raven/DocumentsByEntityName", new IndexQuery
					{
						Query = "Tag:[[Users]]",
						PageSize = 10
					}, CancellationToken.None);
				} while (queryResult.IsStale);
				Assert.Equal(3, queryResult.Results.Count);
			}
		}
Ejemplo n.º 21
0
		public QueryingOnStaleIndexes()
		{
			store = NewDocumentStore();
			db = store.DocumentDatabase;
			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
		}
Ejemplo n.º 22
0
		public MapReduce()
		{
			store = NewDocumentStore();
			db = store.DocumentDatabase;
			db.PutIndex("CommentsCountPerBlog", new IndexDefinition{Map = map, Reduce = reduce, Indexes = {{"blog_id", FieldIndexing.NotAnalyzed}}});
		}
Ejemplo n.º 23
0
		public RavenDB_1007_standard_backup()
		{
			IOExtensions.DeleteDirectory(BackupDir);

			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false,
			});
			db.SpinBackgroundWorkers();
			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
		}