Esempio n. 1
0
        /// <summary>
        /// 搜索自动完成
        /// </summary>
        /// <param name="keyword">关键词</param>
        /// <param name="topNumber">数目</param>
        /// <returns></returns>
        public JsonResult SearchAutoComplete(string keyword, int topNumber)
        {
            PhotoSearcher        photoSearcher = (PhotoSearcher)SearcherFactory.GetSearcher(PhotoSearcher.CODE);
            IEnumerable <string> terms         = photoSearcher.AutoCompleteSearch(keyword, topNumber);

            return(Json(terms.Select(t => new { tagName = t, tagNameWithHighlight = SearchEngine.Highlight(keyword, string.Join("", t.Take(34)), 100) }), JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
 /// <summary>
 /// 为照片添加标签时触发
 /// </summary>
 private void AddTagsToPhoto_BatchAfter(IEnumerable <string> senders, TagEventArgs eventArgs)
 {
     if (eventArgs.TenantTypeId == TenantTypeIds.Instance().Photo())
     {
         long photoId = eventArgs.ItemId;
         if (photoSearcher == null)
         {
             photoSearcher = (PhotoSearcher)SearcherFactory.GetSearcher(PhotoSearcher.CODE);
         }
         photoSearcher.Update(new PhotoService().GetPhoto(photoId));
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 全文检索瀑布流
        /// </summary>
        /// <param name="query"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public ActionResult _SearchWaterFall(PhotoFullTextQuery query, int pageIndex = 1, int pageSize = 20)
        {
            query.TenantTypeId = TenantTypeIds.Instance().User();
            query.PageSize     = pageSize;
            query.PageIndex    = pageIndex;
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser != null && currentUser.UserId == query.UserId)
            {
                query.IgnoreAuditAndPrivacy = true;
            }

            //调用搜索器进行搜索
            PhotoSearcher         photoSearcher = (PhotoSearcher)SearcherFactory.GetSearcher(PhotoSearcher.CODE);
            PagingDataSet <Photo> photos        = photoSearcher.Search(query);

            return(View(photos));
        }
Esempio n. 4
0
        /// <summary>
        /// 照片全局搜索
        /// </summary>
        /// <param name="query">搜索条件</param>
        /// <param name="topNumber">显示数目</param>
        /// <returns></returns>
        public ActionResult _GlobalSearch(PhotoFullTextQuery query, int topNumber)
        {
            query.TenantTypeId = TenantTypeIds.Instance().User();
            query.PageIndex    = 1;
            query.PageSize     = 20;
            PhotoSearcher         photoSearcher = (PhotoSearcher)SearcherFactory.GetSearcher(PhotoSearcher.CODE);
            PagingDataSet <Photo> photos        = photos = photoSearcher.Search(query);

            List <Photo> list = new List <Photo>();

            foreach (var item in photos)
            {
                if (authorizer.Photo_Search(item.Album))
                {
                    list.Add(item);
                }
            }
            ViewData["photoSearcherUrl"] = photoSearcher.PageSearchActionUrl(query.Keyword);
            ViewData["total"]            = photos.TotalRecords;
            ViewData["queryDuration"]    = photos.QueryDuration;
            return(View(list.Take(topNumber)));
        }
Esempio n. 5
0
 //照片增加、删除、更新、设置精华、取消精华
 private void Photo_After(Photo photo, CommonEventArgs eventArgs)
 {
     if (photo == null)
     {
         return;
     }
     if (photoSearcher == null)
     {
         photoSearcher = (PhotoSearcher)SearcherFactory.GetSearcher(PhotoSearcher.CODE);
     }
     if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
     {
         photoSearcher.Insert(photo);
     }
     else if (eventArgs.EventOperationType == EventOperationType.Instance().Update() || eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved())
     {
         photoSearcher.Update(photo);
     }
     else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
     {
         photoSearcher.Delete(photo);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// 快捷搜索
        /// </summary>
        /// <param name="query"></param>
        /// <param name="topNumber"></param>
        /// <returns></returns>
        public ActionResult _QuickSearch(PhotoFullTextQuery query, int topNumber)
        {
            query.TenantTypeId = TenantTypeIds.Instance().User();
            query.PageSize     = 20;
            query.Keyword      = WebUtility.HtmlDecode(query.Keyword);
            query.Filter       = PhotoSearchRange.DESCRIPTION;

            PhotoSearcher         photoSearcher = (PhotoSearcher)SearcherFactory.GetSearcher(PhotoSearcher.CODE);
            PagingDataSet <Photo> photos        = photoSearcher.Search(query);

            List <Photo> list = new List <Photo>();

            foreach (var item in photos)
            {
                if (authorizer.Photo_Search(item.Album))
                {
                    list.Add(item);
                }
            }
            ViewData["total"]            = photos.TotalRecords;
            ViewData["photoSearcherUrl"] = photoSearcher.PageSearchActionUrl(query.Keyword);

            return(View(list.Take(topNumber)));
        }
Esempio n. 7
0
        /// <summary>
        /// 照片搜索
        /// </summary>
        /// <param name="query">条件</param>
        /// <returns></returns>
        public ActionResult Search(PhotoFullTextQuery query)
        {
            query.Keyword      = WebUtility.UrlDecode(query.Keyword);
            query.TenantTypeId = TenantTypeIds.Instance().User();
            query.PageSize     = 20;
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser != null)
            {
                if (currentUser.UserId == query.UserId)
                {
                    query.IgnoreAuditAndPrivacy = true;
                }
            }


            ViewData["keyword"] = query.Keyword;
            ViewData["filter"]  = query.Filter;
            ViewData["userId"]  = query.UserId;

            //调用搜索器进行搜索
            PhotoSearcher         photoSearcher = (PhotoSearcher)SearcherFactory.GetSearcher(PhotoSearcher.CODE);
            PagingDataSet <Photo> photos        = photoSearcher.Search(query);

            int minus = 0;

            foreach (var photo in photos)
            {
                bool isCurrentUser = true;
                if (currentUser != null)
                {
                    isCurrentUser = query.UserId == currentUser.UserId ? true : photo.AuditStatus == AuditStatus.Success;
                }
                if (!(authorizer.Photo_Search(photo.Album) && isCurrentUser))
                {
                    minus++;
                }
            }
            ViewData["minus"] = minus;

            //添加到用户搜索历史记录

            if (currentUser != null)
            {
                if (!string.IsNullOrWhiteSpace(query.Keyword))
                {
                    searchHistoryService.SearchTerm(currentUser.UserId, PhotoSearcher.CODE, query.Keyword);
                }
            }

            //添加到热词
            if (!string.IsNullOrWhiteSpace(query.Keyword))
            {
                searchedTermService.SearchTerm(PhotoSearcher.CODE, query.Keyword);
            }

            //设置页面Meta
            if (string.IsNullOrWhiteSpace(query.Keyword))
            {
                pageResourceManager.InsertTitlePart("照片搜索");
            }
            else
            {
                pageResourceManager.InsertTitlePart(query.Keyword + "的相关照片");
            }

            return(View(photos));
        }