private void AddIndexingTask(DocumentStorageActions actions, JToken metadata, Func <Task> taskGenerator) { foreach (var indexName in IndexDefinitionStorage.IndexNames) { var viewGenerator = IndexDefinitionStorage.GetViewGenerator(indexName); if (viewGenerator == null) { continue; } var entityName = metadata.Value <string>("Raven-Entity-Name"); if (viewGenerator.ForEntityName != null && viewGenerator.ForEntityName != entityName) { continue; } var task = taskGenerator(); task.Index = indexName; actions.AddTask(task); } }
private void AddIndexingTask(DocumentStorageActions actions, JToken metadata, Func<Task> taskGenerator) { foreach (var indexName in IndexDefinitionStorage.IndexNames) { var viewGenerator = IndexDefinitionStorage.GetViewGenerator(indexName); if(viewGenerator==null) continue; var entityName = metadata.Value<string>("Raven-Entity-Name"); if(viewGenerator.ForEntityName != null && viewGenerator.ForEntityName != entityName) continue; var task = taskGenerator(); task.Index = indexName; actions.AddTask(task); } }
public override void IndexDocuments( AbstractViewGenerator viewGenerator, IEnumerable <dynamic> documents, WorkContext context, DocumentStorageActions actions) { actions.SetCurrentIndexStatsTo(name); var count = 0; Func <object, object> documentIdFetcher = null; var reduceKeys = new HashSet <string>(); var documentsWrapped = documents.Select(doc => { var documentId = doc.__document_id; foreach (var reduceKey in actions.DeleteMappedResultsForDocumentId((string)documentId, name)) { reduceKeys.Add(reduceKey); } return(doc); }); foreach (var doc in RobustEnumeration(documentsWrapped, viewGenerator.MapDefinition, actions, context)) { count++; documentIdFetcher = CreateDocumentIdFetcherIfNeeded(documentIdFetcher, doc); var docIdValue = documentIdFetcher(doc); if (docIdValue == null) { throw new InvalidOperationException("Could not find document id for this document"); } var reduceValue = viewGenerator.GroupByExtraction(doc); if (reduceValue == null) { log.DebugFormat("Field {0} is used as the reduce key and cannot be null, skipping document {1}", viewGenerator.GroupByExtraction, docIdValue); continue; } var reduceKey = ReduceKeyToString(reduceValue); var docId = docIdValue.ToString(); reduceKeys.Add(reduceKey); string data = GetMapedData(doc); log.DebugFormat("Mapped result for '{0}': '{1}'", name, data); var hash = ComputeHash(name, reduceKey); actions.PutMappedResult(name, docId, reduceKey, data, hash); actions.IncrementSuccessIndexing(); } foreach (var reduceKey in reduceKeys) { actions.AddTask(new ReduceTask { Index = name, ReduceKey = reduceKey }); } log.DebugFormat("Mapped {0} documents for {1}", count, name); }
public override void IndexDocuments( AbstractViewGenerator viewGenerator, IEnumerable<dynamic> documents, WorkContext context, DocumentStorageActions actions) { actions.SetCurrentIndexStatsTo(name); var count = 0; Func<object, object> documentIdFetcher = null; var reduceKeys = new HashSet<string>(); var documentsWrapped = documents.Select(doc => { var documentId = doc.__document_id; foreach (var reduceKey in actions.DeleteMappedResultsForDocumentId((string)documentId, name)) { reduceKeys.Add(reduceKey); } return doc; }); foreach (var doc in RobustEnumeration(documentsWrapped, viewGenerator.MapDefinition, actions, context)) { count++; documentIdFetcher = CreateDocumentIdFetcherIfNeeded(documentIdFetcher, doc); var docIdValue = documentIdFetcher(doc); if (docIdValue == null) throw new InvalidOperationException("Could not find document id for this document"); var reduceValue = viewGenerator.GroupByExtraction(doc); if (reduceValue == null) { log.DebugFormat("Field {0} is used as the reduce key and cannot be null, skipping document {1}", viewGenerator.GroupByExtraction, docIdValue); continue; } var reduceKey = ReduceKeyToString(reduceValue); var docId = docIdValue.ToString(); reduceKeys.Add(reduceKey); string data = GetMapedData(doc); log.DebugFormat("Mapped result for '{0}': '{1}'", name, data); var hash = ComputeHash(name, reduceKey); actions.PutMappedResult(name, docId, reduceKey, data, hash); actions.IncrementSuccessIndexing(); } foreach (var reduceKey in reduceKeys) { actions.AddTask(new ReduceTask { Index = name, ReduceKey = reduceKey }); } log.DebugFormat("Mapped {0} documents for {1}", count, name); }
private void AddIndexAndEnqueueIndexingTasks(DocumentStorageActions actions, string indexName) { actions.AddIndex(indexName); var firstAndLast = actions.FirstAndLastDocumentIds(); if (firstAndLast.Item1 != 0 && firstAndLast.Item2 != 0) { for (var i = firstAndLast.Item1; i <= firstAndLast.Item2; i += Configuration.IndexingBatchSize) { actions.AddTask(new IndexDocumentRangeTask { FromId = i, ToId = Math.Min(i + Configuration.IndexingBatchSize, firstAndLast.Item2), Index = indexName }); } } workContext.ShouldNotifyAboutWork(); }