コード例 #1
0
        public static tbl_labourerdata FindById(int labourerId)
        {
            _connectionToEs = new ConnectionToES();
            var client = _connectionToEs.EsClient();

            var response = client.Search <tbl_labourerdata>(s => s
                                                            .Index("moll_labourers")
                                                            .Type("Labourer")
                                                            .Query(q => q
                                                                   .Match(m => m
                                                                          .Field(f => f.fld_labourerid)
                                                                          .Query(labourerId.ToString())
                                                                          )
                                                                   )
                                                            );


            var datasend = (from hits in response.Hits
                            select hits.Source).ToList();


            List <tbl_labourerdata> result = response.Documents.ToList();

            return(result[0]);
        }
コード例 #2
0
        public IActionResult  GetValues()
        {
            Value tempPerson = null;
            var   values     = ConnectionToES.ESClinet().Search <Value>(s => s
                                                                        .Index("people")
                                                                        .Type("person")
                                                                        .From(0)
                                                                        .Size(1000)
                                                                        .Query(q => q.MatchAll()));

            var          persons    = values.Hits.ToList();
            List <Value> personList = new List <Value>();

            foreach (var item in persons)
            {
                tempPerson = new Value
                {
                    ID   = item.Source.ID,
                    Name = item.Source.Name
                };
                personList.Add(tempPerson);
            }



            return(Ok(personList));
        }
コード例 #3
0
        public static List <OfferedLabourerService> mostBought()
        {
            _connectionToEs = new ConnectionToES();
            var client = _connectionToEs.EsClient();

            Nest.ISearchResponse <OfferedLabourerService> response = client.Search <OfferedLabourerService>(s => s
                                                                                                            .Index("moll_ols")
                                                                                                            .Type("OLS")
                                                                                                            .Size(20)
                                                                                                            .Query(q => new BoolQuery {
            })
                                                                                                            .Sort(so => so
                                                                                                                  .Field(f => f
                                                                                                                         .Field(ff => ff.fld_timesbought)
                                                                                                                         .Order(SortOrder.Ascending)
                                                                                                                         )
                                                                                                                  )
                                                                                                            .Size(6)
                                                                                                            );

            var datasend = (from hits in response.Hits
                            select hits.Source).ToList();

            List <OfferedLabourerService> packages = response.Documents.ToList <OfferedLabourerService>();

            foreach (OfferedLabourerService package in packages)
            {
                package.fld_cost = package.fld_cost / 100;
            }

            return(response.Documents.ToList <OfferedLabourerService>());
        }
コード例 #4
0
        public static List <tbl_userdata> AllUsers()
        {
            _connectionToEs = new ConnectionToES();
            var client = _connectionToEs.EsClient();



            BoolQuery boolQuery1 = new BoolQuery
            {
            };

            Nest.ISearchResponse <tbl_userdata> response = client.Search <tbl_userdata>(s => s
                                                                                        .Index("moll_users")
                                                                                        .Type("User")
                                                                                        .Query(q => q
                                                                                               .MatchAll()

                                                                                               )
                                                                                        .From(0)
                                                                                        .Size(1000)
                                                                                        );

            var json = client.RequestResponseSerializer.SerializeToString(boolQuery1);


            var datasend = (from hits in response.Hits
                            select hits.Source).ToList();

            List <tbl_userdata> packages = response.Documents.ToList <tbl_userdata>();


            return(response.Documents.ToList <tbl_userdata>());
        }
コード例 #5
0
        //From small searchbar in navigation

        public static List <OfferedLabourerService> simpleSearch(string input)
        {
            //Get the client
            _connectionToEs = new ConnectionToES();
            var client = _connectionToEs.EsClient();


            var result = client.Search <OfferedLabourerService>(x => x                            // use search method
                                                                .Query(q => q                     // define query
                                                                       .MultiMatch(mp => mp       // of type MultiMatch
                                                                                   .Query(input)  // pass text
                                                                                   .Fields(f => f // define fields to search against
                                                                                           .Fields(f1 => f1.fld_name, f2 => f2.fld_description, f3 => f3.fld_category)))));



            List <OfferedLabourerService> packages = result.Documents.ToList <OfferedLabourerService>();

            foreach (OfferedLabourerService package in packages)
            {
                package.fld_cost = package.fld_cost / 100;
            }

            return(packages);
        }
コード例 #6
0
        public static OfferedLabourerService findByOfferedServiceId(int id)
        {
            _connectionToEs = new ConnectionToES();
            var client = _connectionToEs.EsClient();


            Nest.ISearchResponse <OfferedLabourerService> response = client.Search <OfferedLabourerService>(s => s
                                                                                                            .Index("moll_ols")
                                                                                                            .Type("OLS")
                                                                                                            .Size(1)
                                                                                                            .Query(q => q
                                                                                                                   .Match(m => m
                                                                                                                          .Field(f => f.fld_offeredserviceid)
                                                                                                                          .Query(id.ToString())
                                                                                                                          )
                                                                                                                   )
                                                                                                            );

            var datasend = (from hits in response.Hits
                            select hits.Source).ToList();

            OfferedLabourerService package = (OfferedLabourerService)response.Documents.ElementAt(0);

            package.fld_cost = package.fld_cost / 100;

            return(package);
        }
コード例 #7
0
        public static void UpdateField(string documentPath, string fieldName, object fieldValue)
        {
            try
            {
                _connectionToEs = new ConnectionToES();
                var client = _connectionToEs.EsClient();

                var scriptParams = new Dictionary <string, object>
                {
                    { fieldName, fieldValue }
                };

                string scriptString = $"ctx._source." + fieldName + " = params." + fieldName;


                var response = client.Update <T>(
                    documentPath //This is your document path
                    , request => request.Script(
                        script =>
                        script.Inline(
                            scriptString

                            )
                        .Params(scriptParams)));


                var json = client.RequestResponseSerializer.SerializeToString(response);
            }
            catch (Exception e)
            {
            }
        }
コード例 #8
0
        public static void DeleteDocument(int id, string type, string index)
        {
            _connectionToEs = new ConnectionToES();
            var client = _connectionToEs.EsClient();

            var responseDelete = client.Delete <T>(id, d => d
                                                   .Type(type)
                                                   .Index(index));
        }
コード例 #9
0
        public IActionResult DeleteAsync(int id)
        {
            var response = ConnectionToES.ESClinet().Delete <Value>(id, d => d
                                                                    .Index("people")
                                                                    .Type("person"));


            return(Ok());
        }
コード例 #10
0
 public void Post([FromBody] Value per)
 {
     Value person = new Value {
         ID = per.ID, Name = per.Name
     };
     var response = ConnectionToES.ESClinet().IndexAsync <Value>(per, i => i
                                                                 .Index("people")
                                                                 .Type("person")
                                                                 );
 }
コード例 #11
0
        public static void InsertDocument(T document, string index, string type, string id)
        {
            try
            {
                _connectionToEs = new ConnectionToES();
                var client = _connectionToEs.EsClient();

                client.Index <T>(document, i => i.Index(index).Id(id).Refresh(Refresh.True));
            }
            catch (Exception e)
            {
            }
        }
コード例 #12
0
        //Generic queries

        //From searchForm

        public static List <OfferedLabourerService> generalSearchQuery(object input, int size)
        {
            //Get the client
            _connectionToEs = new ConnectionToES();
            var client = _connectionToEs.EsClient();

            //Prepare the lists
            List <QueryContainer> mustList = new List <QueryContainer>();

            //Use reflect to get all the properties values and names

            foreach (PropertyInfo property in input.GetType().GetProperties())
            {
                object value = property.GetValue(input);
                if (value != null && value.ToString() != "0" && value.ToString() != "00:00:00" && value.ToString() != "\0")
                {
                    mustList.Add(getFilter(property, input));
                }
            }


            BoolQuery boolQuery1 = new BoolQuery
            {
                Must = mustList,
            };


            var response1 = client.Search <OfferedLabourerService>(s => s
                                                                   .Index("moll_ols")
                                                                   .Type("OLS")
                                                                   .Query(q => boolQuery1)
                                                                   .Size(size));

            var datasend = (from hits in response1.Hits
                            select hits.Source).ToList();

            var json = client.RequestResponseSerializer.SerializeToString(boolQuery1);

            List <OfferedLabourerService> packages = response1.Documents.ToList <OfferedLabourerService>();

            foreach (OfferedLabourerService package in packages)
            {
                package.fld_cost = package.fld_cost / 100;
            }

            return(packages);
        }
コード例 #13
0
        public static void UpsertDocument(T document, string index, string type, int documentId)
        {
            _connectionToEs = new ConnectionToES();
            var client = _connectionToEs.EsClient();

            try
            {
                var responseUpdate = client.Update <T, Object>(document, u => u
                                                               .Index(index)
                                                               .Type(type)
                                                               .Doc(document)
                                                               .DocAsUpsert(true));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
コード例 #14
0
        //Get by LabourerId
        public static List <OfferedLabourerService> getByLabourer(int labourerid)
        {
            _connectionToEs = new ConnectionToES();
            var client = _connectionToEs.EsClient();


            Nest.ISearchResponse <OfferedLabourerService> response = client.Search <OfferedLabourerService>(s => s
                                                                                                            .Index("moll_ols")
                                                                                                            .Type("OLS")
                                                                                                            .Query(q => q
                                                                                                                   .Match(m => m
                                                                                                                          .Field(f => f.fld_labourerid)
                                                                                                                          .Query(labourerid.ToString())
                                                                                                                          )
                                                                                                                   )
                                                                                                            );

            var datasend = (from hits in response.Hits
                            select hits.Source).ToList();

            List <OfferedLabourerService> packages = response.Documents.ToList <OfferedLabourerService>();

            return(packages);
        }
コード例 #15
0
        //Get everything
        public static List <OfferedLabourerService> getAll()
        {
            _connectionToEs = new ConnectionToES();
            var client = _connectionToEs.EsClient();

            var result = client.Search <OfferedLabourerService>(s => s
                                                                .Index("moll_ols")
                                                                .Type("OLS")
                                                                .Query(q => q
                                                                       .MatchAll()
                                                                       )
                                                                .From(0)
                                                                .Size(10000));

            List <OfferedLabourerService> packages = result.Documents.ToList <OfferedLabourerService>();

            foreach (OfferedLabourerService package in packages)
            {
                package.fld_dateofbirth = package.fld_dateofbirth.Substring(0, 10);
                package.fld_cost        = package.fld_cost / 100;
            }

            return(packages);
        }
コード例 #16
0
        public IActionResult GetValue(int id)
        {
            Value tempPerson = null;

            var response = ConnectionToES.ESClinet().Search <Value>(s => s
                                                                    .Index("people")
                                                                    .Type("person")
                                                                    .From(0)
                                                                    .Size(1000)
                                                                    .Query(q => q.Term(fld => fld.ID, id)));

            if (response != null)
            {
                var person = response.Hits.FirstOrDefault();
                tempPerson = new Value
                {
                    ID   = person.Source.ID,
                    Name = person.Source.Name
                };
            }


            return(Ok(tempPerson));
        }
コード例 #17
0
 public ElasticsearchController()
 {
     _connectionToEs = new ConnectionToES();
 }