public static async Task<bool> AddOrUpdateAsync(EKIndex obj) { try { var result = await _client.SearchAsync<EKIndex>(s => s.Query(q => q.QueryString(ss => ss.Query("Id:" + obj.Id)))); EKIndex l = obj; if (result.Total >= 1) { string _id = result.Hits.First().Id; var r = await _client.UpdateAsync<EKIndex>((u) => { u.Id(_id); u.Doc(obj); u.Index(_config.IndexName); return u; }); return r.IsValid; } else { var resoponse = await _client.IndexAsync<EKIndex>(l, (i) => { i.Index(_config.IndexName); return i; }); return resoponse.Created; } } catch(Exception ex) { LogError(ex); } return false; }
public static EKIndex CopyFromDB(EKToday obj) { EKIndex index=null; if(obj!=null && obj.ID>=0) { index = new EKIndex(); index.Abstract = obj.Abstract; index.AccountEmail = obj.AccountEmail; index.AccountEmail_uuid = obj.AccountEmail_uuid.ToString(); index.ArticleType = obj.ArticleType; index.BodyText = obj.BodyText; index.HeadPic = obj.HeadPic; index.HitPoint = obj.HitPoint != null ? obj.HitPoint.Value : 0; index.Id = obj.ID.ToString(); index.IsExotic = obj.IsExotic != null ? obj.IsExotic.Value : false; index.IsPublic = obj.IsPublic != null ? obj.IsPublic.Value : false; if (obj.IsTop != null) index.IsTop = CommonHelper.ToUnixTime(obj.IsTop.Value); index.Keywords = obj.Keywords; if (obj.PublicDate != null) index.PublicDate = CommonHelper.ToUnixTime(obj.PublicDate.Value); index.ReadPoint = obj.ReadPoint != null ? obj.ReadPoint.Value : 0; index.Title = obj.Title; } return index; }