public void SilverlightWasRequested(DocumentDatabase database) { if (database.GetIndexDefinition("Raven/DocumentsByEntityName") == null) { database.PutIndex("Raven/DocumentsByEntityName", new IndexDefinition { Map = @"from doc in docs let Tag = doc[""@metadata""][""Raven-Entity-Name""] select new { Tag, LastModified = (DateTime)doc[""@metadata""][""Last-Modified""] };", Indexes = { {"Tag", FieldIndexing.NotAnalyzed}, {"LastModified", FieldIndexing.NotAnalyzed}, }, Stores = { {"Tag", FieldStorage.No}, {"LastModified", FieldStorage.No} }, TermVectors = { {"Tag", FieldTermVector.No}, {"LastModified", FieldTermVector.No} } }); } }
public static SuggestionQueryResult ExecuteSuggestionQuery(this DocumentDatabase self, string index, SuggestionQuery suggestionQuery) { if (index == "dynamic" || index.StartsWith("dynamic/", StringComparison.OrdinalIgnoreCase)) { var entitName = index == "dynamic" ? null : index.Remove(0, "dynamic/".Length); index = self.FindDynamicIndexName(entitName, new IndexQuery { Query = suggestionQuery.Field + ":" + QuoteIfNeeded(suggestionQuery.Term) }); if (string.IsNullOrEmpty(index)) { throw new InvalidOperationException("Could find no index for the specified query, suggestions will not create a dynamic index, and cannot suggest without an index. Did you forget to query before calling Suggest?"); } } var indexDefinition = self.GetIndexDefinition(index); if (indexDefinition == null) { throw new InvalidOperationException(string.Format("Could not find specified index '{0}'.", index)); } if (indexDefinition.Suggestions.ContainsKey(suggestionQuery.Field) == false && self.Configuration.PreventAutomaticSuggestionCreation) { // if index does not have suggestions defined for this field and server configuration does not allow to create it on the fly // then just return empty result return(new SuggestionQueryResult()); } return(new SuggestionQueryRunner(self).ExecuteSuggestionQuery(index, suggestionQuery)); }
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("Initialied expired document cleaner, will check for expired documents every {0} seconds", deleteFrequencyInSeconds); timer = new Timer(TimerCallback, null, TimeSpan.FromSeconds(deleteFrequencyInSeconds), TimeSpan.FromSeconds(deleteFrequencyInSeconds)); }
public void SilverlightWasRequested(DocumentDatabase database) { if (database.GetIndexDefinition("Raven/DocumentsByEntityName") == null) { database.PutIndex("Raven/DocumentsByEntityName", new IndexDefinition { Map = @"from doc in docs let Tag = doc[""@metadata""][""Raven-Entity-Name""] select new { Tag, LastModified = (DateTime)doc[""@metadata""][""Last-Modified""] };", Indexes = { { "Tag", FieldIndexing.NotAnalyzed }, { "LastModified", FieldIndexing.NotAnalyzed }, }, Stores = { { "Tag", FieldStorage.No }, { "LastModified", FieldStorage.No } }, TermVectors = { { "Tag", FieldTermVector.No }, { "LastModified", FieldTermVector.No } } }); } }
public void CanDeleteIndex() { db.PutIndex("test", new IndexDefinition { Map = "from doc in docs select new { doc.Name}" }); db.DeleteIndex("test"); Assert.Null(db.GetIndexDefinition("test")); }
private Tuple <string, bool> CreateAutoIndex(string permanentIndexName, Func <IndexDefinition> createDefinition) { if (documentDatabase.GetIndexDefinition(permanentIndexName) != null) { return(Tuple.Create(permanentIndexName, false)); } lock (createIndexLock) { var indexDefinition = createDefinition(); documentDatabase.PutIndex(permanentIndexName, indexDefinition); } return(Tuple.Create(permanentIndexName, true)); }
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); } }
private void FindIndexName(DocumentDatabase database, DynamicQueryMapping map, IndexQuery query) { var targetName = map.ForEntityName ?? "AllDocs"; var combinedFields = String.Join("And", map.Items .OrderBy(x => x.To) .Select(x => x.To)); var indexName = combinedFields; if (map.SortDescriptors != null && map.SortDescriptors.Length > 0) { indexName = string.Format("{0}SortBy{1}", indexName, String.Join("", map.SortDescriptors .Select(x => x.Field) .OrderBy(x => x))); } string groupBy = null; if (AggregationOperation != AggregationOperation.None) { if (query.GroupBy != null && query.GroupBy.Length > 0) { groupBy += "/" + AggregationOperation + "By" + string.Join("And", query.GroupBy); } else { groupBy += "/" + AggregationOperation; } if (DynamicAggregation) { groupBy += "Dynamically"; } } if (database.Configuration.RunInUnreliableYetFastModeThatIsNotSuitableForProduction == false && database.Configuration.RunInMemory == false) { // Hash the name if it's too long (as a path) if ((database.Configuration.DataDirectory.Length + indexName.Length) > 230) { using (var sha256 = SHA256.Create()) { var bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(indexName)); indexName = Convert.ToBase64String(bytes); } } } var permanentIndexName = indexName.Length == 0 ? string.Format("Auto/{0}{1}", targetName, groupBy) : string.Format("Auto/{0}/By{1}{2}", targetName, indexName, groupBy); var temporaryIndexName = indexName.Length == 0 ? string.Format("Temp/{0}{1}", targetName, groupBy) : string.Format("Temp/{0}/By{1}{2}", targetName, indexName, groupBy); // If there is a permanent index, then use that without bothering anything else var permanentIndex = database.GetIndexDefinition(permanentIndexName); map.PermanentIndexName = permanentIndexName; map.TemporaryIndexName = temporaryIndexName; map.IndexName = permanentIndex != null ? permanentIndexName : temporaryIndexName; }
private void FindIndexName(DocumentDatabase database, DynamicQueryMapping map, IndexQuery query) { var targetName = map.ForEntityName ?? "AllDocs"; var combinedFields = String.Join("And", map.Items .OrderBy(x => x.To) .Select(x => x.To)); var indexName = combinedFields; if (map.SortDescriptors != null && map.SortDescriptors.Length > 0) { indexName = string.Format("{0}SortBy{1}", indexName, String.Join("", map.SortDescriptors .Select(x => x.Field) .OrderBy(x => x))); } if (map.HighlightedFields != null && map.HighlightedFields.Length > 0) { indexName = string.Format("{0}Highlight{1}", indexName, string.Join("", map.HighlightedFields.OrderBy(x => x))); } string groupBy = null; if (AggregationOperation != AggregationOperation.None) { if (query.GroupBy != null && query.GroupBy.Length > 0) { groupBy += "/" + AggregationOperation + "By" + string.Join("And", query.GroupBy); } else { groupBy += "/" + AggregationOperation; } if (DynamicAggregation) groupBy += "Dynamically"; } if (database.Configuration.RunInUnreliableYetFastModeThatIsNotSuitableForProduction == false && database.Configuration.RunInMemory == false) { // Hash the name if it's too long (as a path) if ((database.Configuration.DataDirectory.Length + indexName.Length) > 230) { using (var sha256 = SHA256.Create()) { var bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(indexName)); indexName = Convert.ToBase64String(bytes); } } } var permanentIndexName = indexName.Length == 0 ? string.Format("Auto/{0}{1}", targetName, groupBy) : string.Format("Auto/{0}/By{1}{2}", targetName, indexName, groupBy); var temporaryIndexName = indexName.Length == 0 ? string.Format("Temp/{0}{1}", targetName, groupBy) : string.Format("Temp/{0}/By{1}{2}", targetName, indexName, groupBy); // If there is a permanent index, then use that without bothering anything else var permanentIndex = database.GetIndexDefinition(permanentIndexName); map.PermanentIndexName = permanentIndexName; map.TemporaryIndexName = temporaryIndexName; map.IndexName = permanentIndex != null ? permanentIndexName : temporaryIndexName; }
/// <summary> /// Gets the index definition for the specified name /// </summary> /// <param name="name">The name.</param> public IndexDefinition GetIndex(string name) { CurrentOperationContext.Headers.Value = OperationsHeaders; return(database.GetIndexDefinition(name)); }