예제 #1
0
        public static ProfessorIndex GenObject(Guid uuid)
        {
            if (uuid.Equals(Guid.Empty))
                return null;
            ProfessorIndex index = new ProfessorIndex();
            index.Id = uuid.ToString();
            StringBuilder sb = new StringBuilder();
            using (UserRepository repo = new UserRepository())
            {
                var userinfo = repo.GetUserInfoByUuid_TB(uuid);
                if (userinfo.IsBusiness != 0)
                    return null;

                if (userinfo.ResearchFieldId == null)
                    userinfo.ResearchFieldId = 0;

                UserEducation userEducation = new UserEducation();
                userEducation.AccountEmail_uuid = uuid;
                var educationList = repo.GetUserRecords_TB<UserEducation>(userEducation);

                UserAcademic userAc = new UserAcademic();userAc.AccountEmail_uuid = uuid;
                var acadmicList = repo.GetUserRecords_TB<UserAcademic>(userAc);

                //research id
                index.ResearchId = userinfo.ResearchFieldId.Value;
                sb.Append(string.Format("{0} ",userinfo.ResearchFieldId.Value.ToString()));
                //姓名
                index.Name = userinfo.Name;
                sb.Append(string.Format("{0} ", userinfo.Name));
                //研究兴趣
                sb.Append(string.Format("{0} ", userinfo.Interests));
                index.Interests = userinfo.Interests;
                //单位
                sb.Append(string.Format("{0} ", userinfo.Unit));
                index.Danwei = userinfo.Unit;
                //地位
                if (acadmicList!=null && acadmicList.Count>0)
                {
                    List<string> tmp = new List<string>();
                    int diweiScore = 0;
                    foreach(var v in acadmicList)
                    {
                        if(!string.IsNullOrEmpty(v.Association))
                        {
                            if (!tmp.Contains("协会委员"))
                            {
                                tmp.Add("协会委员");
                                diweiScore += 1;
                            }
                        }

                        if (!string.IsNullOrEmpty(v.Fund))
                        {
                            if (!tmp.Contains("基金评审"))
                            {
                                tmp.Add("基金评审");
                                diweiScore += 4;
                            }
                        }

                        if (!string.IsNullOrEmpty(v.Magazine))
                        {
                            if (!tmp.Contains("杂志编委"))
                            {
                                tmp.Add("杂志编委");
                                diweiScore += 2;
                            }
                        }
                    }
                    StringBuilder diweisb = new StringBuilder();
                    foreach(string s in tmp)
                    {
                        sb.Append(string.Format("{0} ", s));
                        diweisb.Append(string.Format("{0} ", s));
                    }
                    index.Diwei = diweisb.ToString();
                    index.DiweiScore = diweiScore;
                }

                //校友
                StringBuilder xiaoyousb = new StringBuilder();
                if(educationList!=null && educationList.Count>0)
                {
                    foreach(var v in educationList)
                    {
                        if(!string.IsNullOrEmpty(v.School))
                        {
                            sb.Append(string.Format("{0} ", v.School));
                            xiaoyousb.Append(string.Format("{0} ", v.School));
                        }
                    }
                    index.Education = xiaoyousb.ToString();
                }
                //地点
                if(!string.IsNullOrEmpty(userinfo.Address))
                {
                    string adress = userinfo.Address.Replace(" ", "").Trim();
                    sb.Append(string.Format("{0} ", adress));
                    index.Address = adress;
                }

                //点击量
                double score = _redis.GetScore<NameCardRedis, NameCardPCountZsetAttribute>(userinfo.uuid.ToString());
                index.AccessCount = score;
            }
            index.KeyWords = sb.ToString();
            return index;
        }
예제 #2
0
 public static bool AddOrUpdate(ProfessorIndex obj)
 {
     try
     {
         var result = _client.Search<ProfessorIndex>(s => s.Query(q => q.QueryString(ss => ss.Query("Id:" + obj.Id))));
         ProfessorIndex l = obj;
         if (result.Total >= 1)
         {
             string _id = result.Hits.First().Id;
             var r = _client.Update<ProfessorIndex>((u) =>
             {
                 u.Id(_id);
                 u.Doc(obj);
                 u.Index(_config.IndexName);
                 return u;
             });
             return r.IsValid;
         }
         else
         {
             var resoponse = _client.Index<ProfessorIndex>(l, (i) => { i.Index(_config.IndexName); return i; });
             return resoponse.Created;
         }
     }
     catch (Exception ex)
     {
         LogError(ex);
     }
     return false;
 }