Esempio n. 1
0
        public async Task IndexPageItemsAsync(IEnumerable <IndexingQueueItem> queueItems)
        {
            var groupedByLanguage = queueItems
                                    .Where(i => !i.Equals(IndexingQueueItem.Empty))
                                    .GroupBy(i => i.Language)
                                    .Where(grouping => !string.IsNullOrWhiteSpace(grouping.Key));

            foreach (IGrouping <string, IndexingQueueItem> grouping in groupedByLanguage)
            {
                Index          index           = this.Client.InitIndex(this.GetPagesIndexName(grouping.Key));
                Language       language        = Language.Parse(grouping.Key);
                List <JObject> objectsToUpdate = new List <JObject>();
                List <string>  objectsToDelete = new List <string>();

                foreach (IndexingQueueItem indexingQueueItem in grouping)
                {
                    if (indexingQueueItem.Deleted)
                    {
                        objectsToDelete.Add(this.crawler.GetObjectId(indexingQueueItem.Id));
                    }
                    else
                    {
                        Item item = this.database.GetItem(ID.Parse(indexingQueueItem.Id), language);

                        if (item != null && item.Versions.Count > 0)
                        {
                            objectsToUpdate.Add(this.crawler.GetJsonForItem(item));
                        }
                    }
                }

                await index.AddObjectsAsync(objectsToUpdate);

                await index.DeleteObjectsAsync(objectsToDelete);
            }
        }