Exemplo n.º 1
0
        private static void ProcessSuggestiveMagazineIndex()
        {
            BulkElasticSuggestiveMagazineIndex =
                new BulkElasticSuggestiveMagazineIndex {
                ElasticSuggestive = new List <ElasticSuggestiveMagazineIndex>()
            };

            foreach (var item in BulkElasticMagazineIndex.ElasticMagazine)
            {
                var elasticMagazine = new ElasticSuggestiveMagazineIndex
                {
                    Title = new Suggest()
                    {
                        Input  = new[] { item.Title },
                        Output = item.Title
                    },
                    Publisher = item.Publisher,
                    Genre     = item.Genre
                };
                BulkElasticSuggestiveMagazineIndex.ElasticSuggestive.Add(elasticMagazine);
            }

            if (BulkElasticSuggestiveMagazineIndex.ElasticSuggestive.Count > 0)
            {
                var elasticmagazineSuggestiveServer = new BulkElasticSuggestiveMagazineIndexMDG();
                elasticmagazineSuggestiveServer.Post(BulkElasticSuggestiveMagazineIndex);
                //Service.Post<BulkElasticSuggestiveMagazineIndex>(BulkElasticSuggestiveMagazineIndex);
            }
        }
        public BulkElasticSuggestiveMagazineIndex Post(BulkElasticSuggestiveMagazineIndex t)
        {
            const int batchCount     = 3000;
            var       timerStopwatch = new Stopwatch();

            timerStopwatch.Start();
            var i = 0;

            Console.WriteLine(@"Elastic suggestive magazine indexing started - ");

            CreateMapping();

            foreach (var elasticTitle in t.ElasticSuggestive.Batch(batchCount))
            {
                i++;
                timerStopwatch.Restart();
                Console.WriteLine(Environment.NewLine);
                Console.WriteLine(@"indexed records - " + i * batchCount);
                ElasticSearch.BulkIndex(elasticTitle.ToList());
                Console.WriteLine(@"iteration {0} took - {1} ms", i, timerStopwatch.ElapsedMilliseconds);
            }
            Console.WriteLine(@"Elastic suggestive magazine indexing finished at - " + timerStopwatch.ElapsedMilliseconds);
            timerStopwatch.Stop();
            return(t);
        }