Example #1
0
        private void PostDocumentsImpl(ICloudBatch batch)
        {
            ICloudSearchIndexSchema schema = _searchIndex.SchemaBuilder?.GetSchema();

            if (schema != null)
            {
                SchemaSynchronizer.EnsureIsInSync(schema.AllFields);
                Schema = new CloudSearchIndexSchema(SchemaSynchronizer.LocalSchemaSnapshot);
                OnSchemaSynced(EventArgs.Empty);
            }
            if (!AvailabilityManager.CanWrite)
            {
                throw new SearchServiceIsUnavailableException(_searchIndex.CloudIndexName, $"The service ${Name} is not available for write operations", null);
            }

            string json = batch.GetJson();

            try
            {
                DocumentOperations.PostDocuments(json);
            }
            catch (PostFailedForSomeDocumentsException ex)
            {
                StringBuilder stringBuilder = new StringBuilder("Post failed for some documents");
                foreach (MultiStatusResponseDocument document1 in ex.Documents)
                {
                    MultiStatusResponseDocument   document           = document1;
                    Dictionary <string, object>   dictionary         = batch.Documents.FirstOrDefault(d => string.Equals((string)d[CloudSearchConfig.VirtualFields.CloudUniqueId], document.Key, StringComparison.OrdinalIgnoreCase));
                    CloudSearchFieldConfiguration fieldConfiguration = _searchIndex.Configuration.FieldMap.GetFieldConfiguration(IDFieldName) as CloudSearchFieldConfiguration;
                    string str = fieldConfiguration == null ? document.Key : (dictionary == null || !dictionary.ContainsKey(fieldConfiguration.CloudFieldName) ? document.Key : dictionary[fieldConfiguration.CloudFieldName].ToString());
                    stringBuilder.AppendLine($"Document id: {str}, message: {document.Message}");
                }
                CrawlingLog.Log.Warn(stringBuilder.ToString(), null);
                CrawlingLog.Log.Debug(ex.RawResponse, null);
            }
        }