示例#1
0
 public static async Task<bool> AddOrUpdateAsync(PapersIndex obj)
 {
     try
     {
         var result = await _client.SearchAsync<PapersIndex>(s => s.Query(q => q.QueryString(ss => ss.Query("Id:" + obj.Id))));
         PapersIndex l = obj;
         if (result.Total >= 1)
         {
             string _id = result.Hits.First().Id;
             var r = await _client.UpdateAsync<PapersIndex>((u) =>
             {
                 u.Id(_id);
                 u.Doc(obj);
                 u.Index(_config.IndexName);
                 return u;
             });
             return r.IsValid;
         }
         else
         {
             var resoponse = await _client.IndexAsync<PapersIndex>(l, (i) => { i.Index(_config.IndexName); return i; });
             return resoponse.Created;
         }
     }
     catch (Exception ex)
     {
         LogError(ex);
     }
     return false;
 }
示例#2
0
        public static PapersIndex CopyFromDB(UserArticle obj)
        {
            PapersIndex index = null;
            if (obj != null && obj.Id > 0)
            {
                index = new PapersIndex();
                index.Id = obj.Id.ToString();
                index.AccountEmail_uuid = obj.AccountEmail_uuid.ToString();
                index.ArticlePath = obj.ArticlePath;
                index.Author = obj.Author;
                index.PostMagazine = obj.PostMagazine != null ? obj.PostMagazine : "";
                if (obj.PublishTime != null)
                    index.PublishTime = CommonHelper.ToUnixTime(obj.PublishTime.Value);
                index.Title = obj.Title;
                index.KeyWords = index.Author.ToLower() + " " + index.PostMagazine.ToLower() + " " + index.Title.ToLower();
                using (DB.Repositorys.UserRepository repo = new DB.Repositorys.UserRepository())
                {
                    index.ResearchFieldId = (repo.GetUserInfoByUuid(obj.AccountEmail_uuid))?.ResearchFieldId ?? 0;
                }

            }
            return index;
        }