public async Task Get_Version_ByKeyAsync()
        {
            //arrange
            string Key = "customer.3";

            var options = new DbContextOptionsBuilder <HistoryContext>()
                          .UseInMemoryDatabase(databaseName: "MyData3").Options;

            // Seed Data
            using (var context = new HistoryContext(options))
            {
                context.HistoryData.Add(new PayloadModel {
                    Key = "customer.3", FirstName = "siaf", LastName = "manea", Address = "berlin", CreatedDate = DateTime.UtcNow
                });
                context.SaveChanges();
            }

            // Act
            using (var context = new HistoryContext(options))
            {
                SearchHistoryService historyRepository = new SearchHistoryService(context);
                var result = await historyRepository.GetSingleVersion(Key);

                // Assert
                Assert.NotNull(result);
            }
        }
        public async Task Get_All_versionsAsync()
        {
            //arrange
            var options = new DbContextOptionsBuilder <HistoryContext>()
                          .UseInMemoryDatabase(databaseName: "MyData5").Options;

            // Seed Data
            using (var context = new HistoryContext(options))
            {
                context.HistoryData.Add(new PayloadModel {
                    Id = Guid.NewGuid(), Key = "customer.2", FirstName = "siaf", LastName = "manea", Address = "berlin", CreatedDate = DateTime.UtcNow
                });
                context.HistoryData.Add(new PayloadModel {
                    Id = Guid.NewGuid(), Key = "customer.1", FirstName = "siaf", LastName = "manea", Address = "berlin", CreatedDate = DateTime.UtcNow
                });
                context.SaveChanges();
            }
            // Act
            using (var context = new HistoryContext(options))
            {
                SearchHistoryService historyRepository = new SearchHistoryService(context);
                var result = await historyRepository.GetAll();

                // Assert
                Assert.True(result.Count == 2);
            }
        }
Example #3
0
        /// <summary>
        /// 微博搜索
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public ActionResult Search(MicroblogFullTextQuery query)
        {
            query.PageSize = 20;//每页记录数

            //调用搜索器进行搜索
            MicroblogSearcher microblogSearcher = (MicroblogSearcher)SearcherFactory.GetSearcher(MicroblogSearcher.CODE);
            PagingDataSet <MicroblogEntity> microblogEntities = microblogSearcher.Search(query);

            //添加到用户搜索历史
            IUser CurrentUser = UserContext.CurrentUser;

            if (CurrentUser != null)
            {
                SearchHistoryService searchHistoryService = new SearchHistoryService();
                searchHistoryService.SearchTerm(CurrentUser.UserId, MicroblogSearcher.CODE, query.Keyword);
            }
            //添加到热词
            if (!string.IsNullOrWhiteSpace(query.Keyword))
            {
                SearchedTermService searchedTermService = new SearchedTermService();
                searchedTermService.SearchTerm(MicroblogSearcher.CODE, query.Keyword);
            }

            //设置页面Meta
            if (string.IsNullOrWhiteSpace(query.Keyword))
            {
                pageResourceManager.InsertTitlePart("搜索");//设置页面Title
            }
            else
            {
                pageResourceManager.InsertTitlePart('“' + query.Keyword + '”' + "的相关微博");//设置页面Title
            }

            return(View(microblogEntities));
        }
        public async Task No_Version_Exist()
        {
            //arrange
            var options = new DbContextOptionsBuilder <HistoryContext>()
                          .UseInMemoryDatabase(databaseName: "MyData6").Options;

            // Act
            using (var context = new HistoryContext(options))
            {
                SearchHistoryService historyRepository = new SearchHistoryService(context);
                var result = await historyRepository.GetAll();

                // Assert
                Assert.True(result.Count().Equals(0));
            }
        }
Example #5
0
        /// <summary>
        /// 百科搜索
        /// </summary>
        public ActionResult Search(WikiFullTextQuery query)
        {
            query.Keyword  = WebUtility.UrlDecode(query.Keyword);
            query.PageSize = 20;//每页记录数

            //调用搜索器进行搜索
            WikiSearcher             wikiSearcher = (WikiSearcher)SearcherFactory.GetSearcher(WikiSearcher.CODE);
            PagingDataSet <WikiPage> wikiPages    = wikiSearcher.Search(query);

            //添加到用户搜索历史
            IUser CurrentUser = UserContext.CurrentUser;

            if (CurrentUser != null)
            {
                if (!string.IsNullOrWhiteSpace(query.Keyword))
                {
                    SearchHistoryService searchHistoryService = new SearchHistoryService();
                    searchHistoryService.SearchTerm(CurrentUser.UserId, WikiSearcher.CODE, query.Keyword);
                }
            }

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

            //获取站点分类,并设置站点分类的选中项
            IEnumerable <Category> siteCategories   = categoryService.GetRootCategories(TenantTypeIds.Instance().WikiPage());// categoryService.GetOwnerCategories(0, TenantTypeIds.Instance().Wiki());
            SelectList             siteCategoryList = new SelectList(siteCategories.Select(n => new { text = n.CategoryName, value = n.CategoryId }), "value", "text", query.SiteCategoryId);

            ViewData["siteCategoryList"] = siteCategoryList;

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

            return(View(wikiPages));
        }
Example #6
0
        /// <summary>
        /// 日志搜索
        /// </summary>
        public ActionResult Search(BlogFullTextQuery query)
        {
            query.PageSize = 20;//每页记录数

            //调用搜索器进行搜索
            BlogSearcher blogSearcher = (BlogSearcher)SearcherFactory.GetSearcher(BlogSearcher.CODE);
            PagingDataSet <BlogThread> blogThreads = blogSearcher.Search(query);

            //添加到用户搜索历史
            IUser CurrentUser = UserContext.CurrentUser;

            if (CurrentUser != null)
            {
                if (!string.IsNullOrWhiteSpace(query.Keyword))
                {
                    SearchHistoryService searchHistoryService = new SearchHistoryService();
                    searchHistoryService.SearchTerm(CurrentUser.UserId, BlogSearcher.CODE, query.Keyword);
                }
            }

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

            //获取站点分类,并设置站点分类的选中项
            IEnumerable <Category> siteCategories   = categoryService.GetOwnerCategories(0, TenantTypeIds.Instance().BlogThread());
            SelectList             siteCategoryList = new SelectList(siteCategories.Select(n => new { text = n.CategoryName, value = n.CategoryId }), "value", "text", query.SiteCategoryId);

            ViewData["siteCategoryList"] = siteCategoryList;

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

            return(View(blogThreads));
        }
        public async Task Version_Not_Exist()
        {
            //arrange
            string Key = "customer.3";

            var options = new DbContextOptionsBuilder <HistoryContext>()
                          .UseInMemoryDatabase(databaseName: "MyData4").Options;

            // Act
            using (var context = new HistoryContext(options))
            {
                SearchHistoryService historyRepository = new SearchHistoryService(context);
                var result = await historyRepository.GetSingleVersion(Key);

                // Assert
                Assert.Null(result);
            }
        }
Example #8
0
        /// <summary>
        /// 专题搜索
        /// </summary>
        public ActionResult Search(TopicFullTextQuery query)
        {
            query.Keyword  = WebUtility.UrlDecode(query.Keyword);
            query.PageSize = 20;//每页记录数

            //调用搜索器进行搜索
            TopicSearcher groupSearcher        = (TopicSearcher)SearcherFactory.GetSearcher(TopicSearcher.CODE);
            PagingDataSet <TopicEntity> groups = groupSearcher.Search(query);

            //添加到用户搜索历史
            IUser CurrentUser = UserContext.CurrentUser;

            if (CurrentUser != null)
            {
                if (!string.IsNullOrWhiteSpace(query.Keyword))
                {
                    SearchHistoryService searchHistoryService = new SearchHistoryService();
                    searchHistoryService.SearchTerm(CurrentUser.UserId, TopicSearcher.CODE, query.Keyword);
                }
            }

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

            //设置页面Meta
            if (string.IsNullOrWhiteSpace(query.Keyword))
            {
                pageResourceManager.InsertTitlePart("专题搜索");//设置页面Title
            }
            else
            {
                pageResourceManager.InsertTitlePart('“' + query.Keyword + '”' + "的相关专题");//设置页面Title
            }

            return(View(groups));
        }
Example #9
0
        /// <summary>
        /// 资讯搜索
        /// </summary>
        public ActionResult Search(CmsFullTextQuery query)
        {
            query.Keyword  = WebUtility.UrlDecode(query.Keyword);
            query.PageSize = 20;//每页记录数

            //调用搜索器进行搜索
            CmsSearcher cmsSearcher = (CmsSearcher)SearcherFactory.GetSearcher(CmsSearcher.CODE);
            PagingDataSet <ContentItem> contentItems = cmsSearcher.Search(query);

            //添加到用户搜索历史
            IUser CurrentUser = UserContext.CurrentUser;

            if (CurrentUser != null)
            {
                if (!string.IsNullOrWhiteSpace(query.Keyword))
                {
                    SearchHistoryService searchHistoryService = new SearchHistoryService();
                    searchHistoryService.SearchTerm(CurrentUser.UserId, CmsSearcher.CODE, query.Keyword);
                }
            }

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

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

            return(View(contentItems));
        }
 public SearchHistoryController(SearchHistoryService searchHistoryService, IConfiguration config)
 {
     _searchHistoryService = searchHistoryService;
     _config = config;
 }
 public SearchHistoryController(SearchHistoryService searchHistoryService)
 {
     _searchHistoryService = searchHistoryService;
 }