예제 #1
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>());
        }
예제 #2
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>());
        }
예제 #3
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);
        }
예제 #4
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);
        }
        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]);
        }
예제 #6
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)
            {
            }
        }
예제 #7
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));
        }
예제 #8
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)
            {
            }
        }
예제 #9
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);
        }
예제 #10
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;
            }
        }
예제 #11
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);
        }
예제 #12
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);
        }