public void Execute(IESIndex <Offer> context)
        {
            var client         = context.GetClient();
            var searchResponse = client.Search <ESOffer>(s => s
                                                         .From(page)
                                                         .Size(size)
                                                         .Query(q => q
                                                                .Percolate(p => p
                                                                           .Field(f => f.Query)
                                                                           .Document(employee)
                                                                           )
                                                                )
                                                         );

            if (!searchResponse.IsValid)
            {
                this.AddErrors(new QueryExectutionFailedError(searchResponse.DebugInformation));
                return;
            }

            var offers = new List <Offer>();

            foreach (var doc in searchResponse.Documents)
            {
                offers.Add(doc);
            }

            SetValue(offers);
        }
Esempio n. 2
0
        public void Execute(IESIndex <Offer> context)
        {
            var toDelete = this.actions.Where(x => x.Action == CRUDActionType.Delete).Select(x => (ESOffer)x.Entity).ToList();
            var toCreate = this.actions.Where(x => x.Action == CRUDActionType.Create).Select(x => (ESOffer)x.Entity).ToList();

            Console.WriteLine("OFFER BATCH CREATE:" + toCreate.Count());

            var toUpdate = this.actions.Where(x => x.Action == CRUDActionType.Update).Select(x => (ESOffer)x.Entity).ToList();

            var client = context.GetClient();
            var result = client.Bulk(x => {
                if (toCreate.Any())
                {
                    x = x.IndexMany(toCreate, (a, b) => { return(a.Id(b.Id)); });
                }

                if (toUpdate.Any())
                {
                    x = x.UpdateMany(toUpdate, (a, b) => { return(a.Id(b.Id)); });
                }

                if (toDelete.Any())
                {
                    x = x.DeleteMany(toDelete, (a, b) => { return(a.Id(b.Id)); });
                }

                return(x);
            });

            if (!result.IsValid)
            {
                Console.WriteLine("OFFER BATCH ERROR:" + result.DebugInformation);
                return;
            }
        }
Esempio n. 3
0
        public void Execute(IESIndex <Employee> context)
        {
            var toDelete = this.actions.Where(x => x.Action == CRUDActionType.Delete).Select(x => (ESEmployee)x.Entity).ToList();
            var toCreate = this.actions.Where(x => x.Action == CRUDActionType.Create).Select(x => (ESEmployee)x.Entity).ToList();
            var toUpdate = this.actions.Where(x => x.Action == CRUDActionType.Update).Select(x => (ESEmployee)x.Entity).ToList();

            var client = context.GetClient();
            var result = client.Bulk(x => {
                if (toCreate.Any())
                {
                    x = x.IndexMany(toCreate, (a, b) => { return(a.Id(b.Id)); });
                }

                if (toUpdate.Any())
                {
                    x = x.IndexMany(toUpdate, (a, b) => { return(a.Id(b.Id)); });
                }

                if (toDelete.Any())
                {
                    x = x.DeleteMany(toDelete, (a, b) => { return(a.Id(b.Id)); });
                }

                return(x);
            });

            if (!result.IsValid)
            {
                this.AddErrors(new QueryExectutionFailedError(result.DebugInformation));
            }
        }
Esempio n. 4
0
        public void Execute(IESIndex <Employee> context)
        {
            var client         = context.GetClient();
            var searchResponse = client.Search <ESEmployee>(s => s
                                                            .From(page)
                                                            .Size(size)
                                                            .Query(q => q
                                                                   .MultiMatch(mp => mp
                                                                               .Query(search)
                                                                               .Fields(f => f
                                                                                       .Fields(f1 => f1.Name, f2 => f2.JobTitle))))

                                                            );

            if (!searchResponse.IsValid)
            {
                this.AddErrors(new QueryExectutionFailedError(searchResponse.DebugInformation));
                return;
            }

            var employees = new List <Employee>();

            foreach (var doc in searchResponse.Documents)
            {
                employees.Add(doc);
            }

            SetValue(employees);
        }
        public void Execute(IESIndex <Employee> context)
        {
            var client = context.GetClient();
            var query  = new QueryContainer();

            foreach (var skill in offer.RequaredSkills)
            {
                query &= new MatchQuery {
                    Field = new Field("skills.id"),
                    Query = skill.Id.ToString()
                };
            }
            var searchResponse = client.Search <ESEmployee>(s => s
                                                            .From(page)
                                                            .Size(size)
                                                            .Query(q => query)
                                                            );

            if (!searchResponse.IsValid)
            {
                this.AddErrors(new QueryExectutionFailedError(searchResponse.DebugInformation));
                return;
            }

            var employees = new List <Employee>();

            foreach (var doc in searchResponse.Documents)
            {
                employees.Add(doc);
            }

            SetValue(employees);
        }
Esempio n. 6
0
        public ClientProvider(IHttpContextAccessor accessor,
                              IDistributedCache cache,
                              ElasticClient esSvcClient)
        {
            _esClient = new ESIndex_Client(esSvcClient);

            try{
                var host = accessor.HttpContext.Request.Path.ToString().Split('/');
                _clientUrlCode = host[1];
            }
            catch {
                _clientUrlCode = "icu";
            }

            if (_clientUrlCode.Equals("Manage", StringComparison.OrdinalIgnoreCase))
            {
                _clientId   = 0;
                _clientName = "SRS";
                return;
            }

            var cacheEntry = cache.Get(_clientUrlCode + "_name");

            if (cacheEntry == null || !cacheEntry.Any())
            {
                var esResponse = _esClient.Search <ESIndex_Client_Document>(
                    new SearchRequest <ESIndex_Client_Document> {
                    Query = new BoolQuery {
                        Filter = new List <QueryContainer> {
                            new TermQuery {
                                Field = "urlCode",
                                Value = _clientUrlCode
                            }
                        }
                    },
                    Size = 1
                }
                    );

                var client = esResponse.Documents.First();
                _clientName = client.Name;
                _clientId   = client.Id;

                cache.SetAsync(_clientUrlCode + "_name", Encoding.ASCII.GetBytes(_clientName));
                cache.SetAsync(_clientUrlCode + "_id", BitConverter.GetBytes(_clientId));
            }
            else
            {
                _clientName = Encoding.ASCII.GetString(cacheEntry);
                cacheEntry  = cache.Get(_clientUrlCode + "_id");
                _clientId   = BitConverter.ToInt32(cacheEntry, 0);
            }
        }
Esempio n. 7
0
        public StoresController(tt_apps_srs_db_context db,
                                IClientProvider client,
                                ElasticClient esSvcClient)
        {
            _db              = db;
            _client_id       = client.ClientId;
            _client_name     = client.Name;
            _client_url_code = client.UrlCode;
            _client          = client;

            _esStoreClient = new ESIndex_Store(esSvcClient);
        }
        public void Execute(IESIndex <Employee> context)
        {
            var toDelete = this.actions.Where(x => x.Action == CRUDActionType.Delete).Select(x => x.Entity).ToList();
            var toCreate = this.actions.Where(x => x.Action == CRUDActionType.Create).Select(x => x.Entity).ToList();
            var toUpdate = this.actions.Where(x => x.Action == CRUDActionType.Update).Select(x => x.Entity).ToList();

            var client = context.GetClient();

            client.Bulk(x => x.IndexMany(toCreate, (a, b) => { return(a.Id(b.Id)); })
                        .UpdateMany(toUpdate, (a, b) => { return(a.Id(b.Id)); })
                        .DeleteMany(toDelete, (a, b) => { return(a.Id(b.Id)); }));
        }
Esempio n. 9
0
        public void Execute(IESIndex <Offer> context)
        {
            var client   = context.GetClient();
            var response = client.Search <ESOffer>(s => s
                                                   .From(0)
                                                   .Size(0)
                                                   .Query(q => q
                                                          .MatchAll())
                                                   );

            if (!response.IsValid)
            {
                this.AddErrors(new QueryExectutionFailedError(response.DebugInformation));
                return;
            }

            this.SetValue(response.Total);
        }
        public void Execute(IESIndex <Employee> context)
        {
            var client   = context.GetClient();
            var response = client.Search <ESEmployee>(s => s
                                                      .Aggregations(a => a.Terms("skills", t => t.Field(p => p.Skills.First().Id))));

            if (!response.IsValid)
            {
                this.AddErrors(new QueryExectutionFailedError(response.DebugInformation));
                return;
            }

            var skills = response.Aggregations.Terms("skills");
            var result = new Dictionary <string, long>();

            foreach (var item in skills.Buckets)
            {
                result.Add(item.Key, item.DocCount.GetValueOrDefault());
            }

            this.SetValue(result);
        }
Esempio n. 11
0
 public static ElasticClient GetClient <TEntity>(this IESIndex <TEntity> index)
 {
     return(((ESIndex <TEntity>)index).Client);
 }