PutIndex() public method

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

		}
		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));

		}
Example #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}}});
		}
Example #5
0
		public BackupRestore()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false
			});
			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
		}
Example #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();
 }
Example #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());
		}
		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()));
		}
Example #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());
		}
Example #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 };
                "
                        });
        }
Example #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 };
				"
						});
		}
Example #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 };
                "
                        });
        }
Example #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}"
						});
		}
Example #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);
        }
Example #17
0
		public QueryingOnDefaultIndex()
		{
			db = new DocumentDatabase(new RavenConfiguration {DataDirectory = DataDir, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true});
			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
			db.SpinBackgroundWorkers();
		}
Example #18
0
		public IndexingBehavior()
		{
			store = NewDocumentStore();
			db = store.DocumentDatabase;
			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
		}
Example #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);
			}
		}
Example #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);
			}
		}
		public QueryingOnStaleIndexes()
		{
			store = NewDocumentStore();
			db = store.DocumentDatabase;
			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
		}
Example #22
0
		public MapReduce()
		{
			store = NewDocumentStore();
			db = store.DocumentDatabase;
			db.PutIndex("CommentsCountPerBlog", new IndexDefinition{Map = map, Reduce = reduce, Indexes = {{"blog_id", FieldIndexing.NotAnalyzed}}});
		}
Example #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());
		}