public List <ThuocTinh> GetManyByGiaTri(IEnumerable <int> lst_gia_tri, LoaiThuocTinh loai, bool is_admin = false) { List <ThuocTinh> lst = new List <ThuocTinh>(); if (lst_gia_tri.Count() > 0) { var re = client.Search <ThuocTinh>(s => s.Query(q => q.Term(t => t.Field("loai").Value(loai)) && q.Terms(t => t.Field("gia_tri").Terms(lst_gia_tri)))); return(re.Hits.Select(x => ConvertDoc(x)).ToList()); } return(lst); }
public bool IsGiaTriThuocTinhExist(LoaiThuocTinh loai, ThuocTinhType type, int gia_tri) { var re = client.Search <ThuocTinh>(s => s .Query(q => q.Term(t => t.Field("trang_thai").Value(TrangThai.ACTIVE)) && q.Term(t => t.Field("gia_tri").Value(gia_tri)) ).Size(0)); if (re.IsValid) { return(re.Total > 0); } return(true); }
public bool IsTenThuocTinhExist(string app_id, LoaiThuocTinh loai, ThuocTinhType type, string ten) { var re = client.Search <ThuocTinh>(s => s.Query(q => q.Term(t => t.Field("app_id.keyword").Value(app_id)) && q.Term(t => t.Field("trang_thai").Value(TrangThai.ACTIVE)) && q.Term(t => t.Field("loai").Value(loai)) && q.Term(t => t.Field("type").Value(type)) && q.Term(t => t.Field("ten.keyword").Value(ten)) ).Size(0)); if (re.IsValid) { return(re.Total > 0); } return(true); }
public IEnumerable <int> GetIdThuocTinhByIdObj(string app_id, string id_obj, LoaiThuocTinh loai_obj, string nguoi_tao) { var re = client.Search <ThuocTinhDuLieu>(s => s.Query(q => q.Term(t => t.Field("app_id.keyword").Value(app_id)) && q.Term(t => t.Field("trang_thai").Value(TrangThai.ACTIVE)) && q.Term(t => t.Field("loai_obj").Value(loai_obj)) && q.Term(t => t.Field("nguoi_tao.keyword").Value(nguoi_tao)) && q.Term(t => t.Field("id_obj.keyword").Value(id_obj))).Source(so => so.Includes(ic => ic.Fields(new string[] { "thuoc_tinh" }))).Size(9999)); if (re.Total > 0) { return(re.Documents.SelectMany(x => x.thuoc_tinh)); } return(new List <int>()); }
public List <ThuocTinh> GetThuocTinhByLoai(LoaiThuocTinh loai, string user, bool is_admin = false) { if (is_admin) { var re = client.Search <ThuocTinh>(s => s .Source(so => so.Includes(ic => ic.Fields(new string[] { "loai", "gia_tri", "nhom", "type", "ten" }))) .Query(q => q.Term(t => t.Field("loai").Value(loai)) ).Size(100)); return(re.Hits.Select(ConvertDoc).ToList()); } else { var re = client.Search <ThuocTinh>(s => s.Source( so => so.Includes(ic => ic.Fields(new string[] { "loai", "gia_tri", "nhom", "type", "ten" }))) .Query(q => q.Term(t => t.Field("loai").Value(loai)) && q.Term(t => t.Field("nguoi_tao").Value(user))).Size(100)); return(re.Hits.Select(ConvertDoc).ToList()); } }
public void UpsertThuocTinhRieng(object o, string id_obj, LoaiThuocTinh loai_obj) { List <int> thuoc_tinh_rieng; try { var obj = JToken.Parse(o.ToString()); if (obj != null && obj["thuoc_tinh_rieng"] != null) { thuoc_tinh_rieng = obj["thuoc_tinh_rieng"].ToObject <List <int> >(); var data = new ThuocTinhDuLieu(); data.id_obj = id_obj; data.loai_obj = loai_obj; data.thuoc_tinh = thuoc_tinh_rieng; data.trang_thai = TrangThai.ACTIVE; SetMetaData(data, false); QLCUNL.BL.ThuocTinhDuLieuBL.Index(data); } } catch (Exception) { } }
public static bool IsGiaTriThuocTinhExist(string app_id, LoaiThuocTinh loai, ThuocTinhType type, int gia_tri) { return(ThuocTinhRepository.Instance.IsGiaTriThuocTinhExist(app_id, loai, type, gia_tri)); }
public List <ThuocTinhDuLieu> GetByLoaiGiaTri(string app_id, string nguoi_tao, IEnumerable <int> thuoc_tinh, LoaiThuocTinh loai, bool is_admin) { if (thuoc_tinh.Count() == 0) { return(new List <ThuocTinhDuLieu>()); } if (is_admin) { var re = client.Search <ThuocTinhDuLieu>(s => s.Query(q => q.Term(t => t.Field("app_id.keyword").Value(app_id)) && q.Term(t => t.Field("loai_obj").Value(loai)) && q.Terms(t => t.Field("thuoc_tinh").Terms(thuoc_tinh)) && q.Term(t => t.Field("trang_thai").Value(TrangThai.ACTIVE)) ).Size(100)); return(re.Documents.ToList()); } else { var re = client.Search <ThuocTinhDuLieu>(s => s.Query(q => q.Term(t => t.Field("app_id.keyword").Value(app_id)) && q.Term(t => t.Field("loai_obj").Value(loai)) && q.Terms(t => t.Field("thuoc_tinh").Terms(thuoc_tinh)) && q.Term(t => t.Field("trang_thai").Value(TrangThai.ACTIVE)) && q.Term(t => t.Field("nguoi_tao.keyword").Value(nguoi_tao)) ).Size(100)); return(re.Documents.ToList()); } }
public Dictionary <int, long> ThongKeTheoThuocTinh(string app_id, string nguoi_tao, LoaiThuocTinh loai, IEnumerable <int> thuoc_tinh, IEnumerable <string> lst_id, IEnumerable <string> lst_should_id, IEnumerable <string> lst_must_not_id, bool is_admin = false, string op = "0") { Dictionary <int, long> dic_thong_ke = new Dictionary <int, long>(); List <QueryContainer> must = new List <QueryContainer>(); List <QueryContainer> should = new List <QueryContainer>(); List <QueryContainer> must_not = new List <QueryContainer>(); must.Add(new TermQuery() { Field = "app_id.keyword", Value = app_id }); must_not.Add(new TermQuery() { Field = "trang_thai", Value = TrangThai.DELETED }); if (lst_must_not_id.Count() > 0) { must_not.Add(new TermsQuery() { Field = "id_obj.keyword", Terms = lst_must_not_id }); } if (!is_admin) { if (lst_should_id.Count() > 0) { must.Add(new TermQuery() { Field = "nguoi_tao.keyword", Value = nguoi_tao } || new TermsQuery() { Field = "id_obj.keyword", Terms = lst_should_id }); } else { must.Add(new TermQuery() { Field = "nguoi_tao.keyword", Value = nguoi_tao }); } } else { if (lst_should_id.Count() > 0) { must.Add(new TermsQuery() { Field = "id_obj.keyword", Terms = lst_should_id }); } } must.Add(new TermQuery() { Field = "loai_obj", Value = loai }); if (thuoc_tinh.Count() > 0) { switch (op) { case "0": must.Add(new TermsQuery() { Field = "thuoc_tinh", Terms = thuoc_tinh.Select(x => (object)x) }); break; case "1": List <QueryContainer> all_thuoc_tinh = new List <QueryContainer>(); foreach (var item in thuoc_tinh) { all_thuoc_tinh.Add(new TermQuery() { Field = "thuoc_tinh", Value = item }); } must.Add(new BoolQuery() { Must = all_thuoc_tinh }); break; case "2": must.Add(!new TermsQuery() { Field = "thuoc_tinh", Terms = thuoc_tinh.Select(x => (object)x) }); break; } } if (lst_id.Count() > 0) { must.Add(new TermsQuery() { Field = "id_obj.keyword", Terms = lst_id }); } SearchRequest req = new SearchRequest(_default_index); req.Query = new QueryContainer(new BoolQuery() { Must = must, MustNot = must_not }); req.From = 0; req.Size = 0; //req.Aggregations = new AggregationDictionary // { // { // "thuoc_tinh", new TermsAggregation("tt") // { // Field="thuoc_tinh",Size=9999 // } // } // }; req.Aggregations = new FilterAggregation("thuoc_tinh") { Filter = new QueryContainer(new BoolQuery() { Must = must, MustNot = must_not }), Aggregations = new TermsAggregation("tt") { Field = "thuoc_tinh" } }; var res = client.Search <ThuocTinhDuLieu>(req); if (res.IsValid) { foreach (var item in res.Aggregations.Filter("thuoc_tinh").Terms("tt").Buckets) { dic_thong_ke.Add(Convert.ToInt32(item.Key), item.DocCount.GetValueOrDefault()); } } return(dic_thong_ke); }
public List <ThuocTinh> GetPrivateByLoaiGiaTri(string app_id, string nguoi_tao, IEnumerable <int> thuoc_tinh, LoaiThuocTinh loai, bool is_admin) { if (thuoc_tinh.Count() == 0) { return(new List <ThuocTinh>()); } if (is_admin) { var re = client.Search <ThuocTinh>(s => s.Source(so => so.Includes(ic => ic.Fields(new string[] { "loai", "gia_tri", "nhom", "type", "ten" }))).Query(q => q.Term(t => t.Field("app_id.keyword").Value(app_id)) && q.Term(t => t.Field("trang_thai").Value(TrangThai.ACTIVE)) && q.Term(t => t.Field("loai").Value(loai)) && q.Terms(t => t.Field("gia_tri").Terms(thuoc_tinh)) && q.Term(t => t.Field("type").Value(ThuocTinhType.PRIVATE)) ).Size(100)); return(re.Documents.ToList()); } else { var re = client.Search <ThuocTinh>(s => s.Source( so => so.Includes(ic => ic.Fields(new string[] { "loai", "gia_tri", "nhom", "type", "ten" }))) .Query(q => q.Term(t => t.Field("app_id.keyword").Value(app_id)) && q.Term(t => t.Field("trang_thai").Value(TrangThai.ACTIVE)) && q.Term(t => t.Field("loai").Value(loai)) && q.Terms(t => t.Field("gia_tri").Terms(thuoc_tinh)) && q.Term(t => t.Field("type").Value(ThuocTinhType.PRIVATE)) && q.Term(t => t.Field("nguoi_tao.keyword").Value(nguoi_tao))).Size(100)); return(re.Documents.ToList()); } }
public List <ThuocTinhDuLieu> Search(string app_id, string nguoi_tao, LoaiThuocTinh loai, List <int> thuoc_tinh, int page, out long total_recs, out string msg, int page_size = 50, string op = "0", List <int> thuoc_tinh2 = null, string op2 = "0") { msg = ""; total_recs = 0; List <ThuocTinhDuLieu> lst = new List <ThuocTinhDuLieu>(); try { List <QueryContainer> must = new List <QueryContainer>(); must.Add(new TermQuery() { Field = "app_id.keyword", Value = app_id }); List <QueryContainer> must_not = new List <QueryContainer>(); must_not.Add(new TermQuery() { Field = "trang_thai", Value = TrangThai.DELETED }); must.Add(new TermQuery() { Field = "loai_obj", Value = loai } && new TermQuery() { Field = "nguoi_tao.keyword", Value = nguoi_tao }); if (thuoc_tinh.Count > 0 && (thuoc_tinh2 != null && thuoc_tinh2.Count > 0)) { List <QueryContainer> all_thuoc_tinh = new List <QueryContainer>(); switch (op) { case "0": // CHỨA BẤT KỲ all_thuoc_tinh.Add(new TermsQuery() { Field = "thuoc_tinh", Terms = thuoc_tinh.Select(x => (object)x) }); break; case "1": // CHỨA TẤT CẢ List <QueryContainer> all_thuoc_tinh2 = new List <QueryContainer>(); foreach (var item in thuoc_tinh) { all_thuoc_tinh2.Add(new TermQuery() { Field = "thuoc_tinh", Value = item }); } all_thuoc_tinh.Add(new BoolQuery() { Must = all_thuoc_tinh2 }); break; case "2": //KHÔNG CHỨA all_thuoc_tinh.Add(!new TermsQuery() { Field = "thuoc_tinh", Terms = thuoc_tinh.Select(x => (object)x) }); break; } switch (op2) { case "0": // CHỨA BẤT KỲ all_thuoc_tinh.Add(new TermsQuery() { Field = "thuoc_tinh", Terms = thuoc_tinh2.Select(x => (object)x) }); break; case "1": // CHỨA TẤT CẢ List <QueryContainer> all_thuoc_tinh2 = new List <QueryContainer>(); foreach (var item in thuoc_tinh2) { all_thuoc_tinh2.Add(new TermQuery() { Field = "thuoc_tinh", Value = item }); } all_thuoc_tinh.Add(new BoolQuery() { Must = all_thuoc_tinh2 }); break; case "2": //KHÔNG CHỨA all_thuoc_tinh.Add(!new TermsQuery() { Field = "thuoc_tinh", Terms = thuoc_tinh2.Select(x => (object)x) }); break; } must.AddRange(all_thuoc_tinh); } else { if (thuoc_tinh.Count > 0) { switch (op) { case "0": must.Add(new TermsQuery() { Field = "thuoc_tinh", Terms = thuoc_tinh.Select(x => (object)x) }); break; case "1": List <QueryContainer> all_thuoc_tinh = new List <QueryContainer>(); foreach (var item in thuoc_tinh) { all_thuoc_tinh.Add(new TermQuery() { Field = "thuoc_tinh", Value = item }); } must.Add(new BoolQuery() { Must = all_thuoc_tinh }); break; case "2": must.Add(!new TermsQuery() { Field = "thuoc_tinh", Terms = thuoc_tinh.Select(x => (object)x) }); break; } } if (thuoc_tinh2 != null && thuoc_tinh2.Count > 0) { switch (op2) { case "0": must.Add(new TermsQuery() { Field = "thuoc_tinh", Terms = thuoc_tinh2.Select(x => (object)x) }); break; case "1": List <QueryContainer> all_thuoc_tinh = new List <QueryContainer>(); foreach (var item in thuoc_tinh2) { all_thuoc_tinh.Add(new TermQuery() { Field = "thuoc_tinh", Value = item }); } must.Add(new BoolQuery() { Must = all_thuoc_tinh }); break; case "2": must.Add(!new TermsQuery() { Field = "thuoc_tinh", Terms = thuoc_tinh2.Select(x => (object)x) }); break; } } } List <ISort> sort = new List <ISort>(); sort.Add(new FieldSort() { Field = "ngay_sua", Order = SortOrder.Descending }); sort.Add(new FieldSort() { Field = "ngay_tao", Order = SortOrder.Descending }); SourceFilter so = new SourceFilter(); so.Includes = new string[] { "id_obj", "thuoc_tinh", "loai_obj" }; SearchRequest req = new SearchRequest(_default_index); req.Query = new QueryContainer(new BoolQuery() { Must = must, MustNot = must_not }); req.From = (page - 1) * page_size; req.Size = page_size; req.Source = so; req.Sort = sort; req.TrackTotalHits = true; var res = client.Search <ThuocTinhDuLieu>(req); if (res.IsValid) { total_recs = res.Total; lst = res.Hits.Select(x => ConvertDoc(x)).ToList(); } } catch (Exception ex) { msg = $"{ex.Message}. Trace: {ex.StackTrace}"; } return(lst); }
public static List <ThuocTinh> GetPrivateByLoaiGiaTri(string app_id, string nguoi_tao, IEnumerable <int> thuoc_tinh, LoaiThuocTinh loai, bool is_admin) { return(ThuocTinhRepository.Instance.GetPrivateByLoaiGiaTri(app_id, nguoi_tao, thuoc_tinh, loai, is_admin)); }
public static List <ThuocTinh> GetManyByGiaTri(string app_id, IEnumerable <int> lst_gia_tri, LoaiThuocTinh loai, int type) { return(ThuocTinhRepository.Instance.GetManyByGiaTri(app_id, lst_gia_tri, loai, type)); }
public static bool IsTenThuocTinhExist(string app_id, LoaiThuocTinh loai, ThuocTinhType type, string ten) { return(ThuocTinhRepository.Instance.IsTenThuocTinhExist(app_id, loai, type, ten)); }
public static List <ThuocTinh> GeSharedtByLoaiGiaTri(string app_id, IEnumerable <int> thuoc_tinh, LoaiThuocTinh loai) { return(ThuocTinhRepository.Instance.GeSharedtByLoaiGiaTri(app_id, thuoc_tinh, loai)); }
public List <ThuocTinh> GeSharedtByLoaiGiaTri(string app_id, IEnumerable <int> thuoc_tinh, LoaiThuocTinh loai) { if (thuoc_tinh.Count() == 0) { return(new List <ThuocTinh>()); } var re = client.Search <ThuocTinh>(s => s.Source(so => so.Includes(ic => ic.Fields(new string[] { "loai", "gia_tri", "nhom", "type", "ten" }))).Query(q => q.Term(t => t.Field("app_id.keyword").Value(app_id)) && q.Term(t => t.Field("trang_thai").Value(TrangThai.ACTIVE)) && q.Term(t => t.Field("loai").Value(loai)) && q.Terms(t => t.Field("gia_tri").Terms(thuoc_tinh)) && q.Term(t => t.Field("type").Value(ThuocTinhType.SHARED)) ).Size(100)); return(re.Documents.ToList()); }
public List <ThuocTinh> GetManyByGiaTri(string app_id, IEnumerable <int> lst_gia_tri, LoaiThuocTinh loai, int type) { List <ThuocTinh> lst = new List <ThuocTinh>(); if (lst_gia_tri.Count() > 0) { if (type > 0) { var re = client.Search <ThuocTinh>(s => s.Query(q => q.Term(t => t.Field("app_id.keyword").Value(app_id)) && q.Term(t => t.Field("trang_thai").Value(TrangThai.ACTIVE)) && q.Term(t => t.Field("loai").Value(loai)) && q.Term(t => t.Field("type").Value(type)) && q.Terms(t => t.Field("gia_tri").Terms(lst_gia_tri)))); return(re.Hits.Select(x => ConvertDoc(x)).ToList()); } else { var re = client.Search <ThuocTinh>(s => s.Query(q => q.Term(t => t.Field("app_id.keyword").Value(app_id)) && q.Term(t => t.Field("trang_thai").Value(TrangThai.ACTIVE)) && q.Term(t => t.Field("loai").Value(loai)) && q.Terms(t => t.Field("gia_tri").Terms(lst_gia_tri)))); return(re.Hits.Select(x => ConvertDoc(x)).ToList()); } } return(lst); }
public static List <ThuocTinhDuLieu> Search(string app_id, string nguoi_tao, LoaiThuocTinh loai, List <int> thuoc_tinh, int page, out long total_recs, out string msg, int page_size = 50, string op = "0", List <int> thuoc_tinh2 = null, string op2 = "0") { return(ThuocTinhDuLieuRepository.Instance.Search(app_id, nguoi_tao, loai, thuoc_tinh, page, out total_recs, out msg, page_size, op, thuoc_tinh2, op2)); }
public static IEnumerable <int> GetIdThuocTinhByIdObj(string app_id, string id_obj, LoaiThuocTinh loai_obj, string nguoi_tao) { return(ThuocTinhDuLieuRepository.Instance.GetIdThuocTinhByIdObj(app_id, id_obj, loai_obj, nguoi_tao)); }
public static Dictionary <int, long> ThongKeTheoThuocTinh(string app_id, string nguoi_tao, LoaiThuocTinh loai, IEnumerable <int> thuoc_tinh, IEnumerable <string> lst_id, IEnumerable <string> lst_should_id, IEnumerable <string> lst_must_not_id, bool is_admin = false, string op = "0") { return(ThuocTinhDuLieuRepository.Instance.ThongKeTheoThuocTinh(app_id, nguoi_tao, loai, thuoc_tinh, lst_id, lst_should_id, lst_must_not_id, is_admin, op)); }