public SearchResult <Worktask> Search(string username, string query, int page, int pageSize)
        {
            int[] boardIdList = KanbanService.GetInstance().UserBoardList(username).Select(b => b.Id).ToArray();
            var   search      = new SearchRequest
            {
                Query = new MultiMatchQuery
                {
                    Query  = query,
                    Fields = Infer.Fields("attachments.attachment_content", "task_title", "task_description", "task_identify")
                },

                Highlight = new Highlight
                {
                    PreTags  = new[] { "<sr>" },
                    PostTags = new[] { "</sr>" },
                    Fields   = new Dictionary <Field, IHighlightField>
                    {
                        { "*", new HighlightField {
                          } }
                    }
                }
            };

            var result     = client.Search <Worktask>(search);
            var highlights = result.Hits.Select(h => new SearchResultItem <Worktask>(h.Highlights, h.Source)).ToList();

            return(new SearchResult <Worktask>
            {
                Total = (int)result.Total,
                Page = page,
                Results = result.Documents.Where(d => boardIdList.Any(i => i == d.BoardID)).ToList(),
                Highlights = highlights.Where(d => boardIdList.Any(i => i == d.Source.BoardID)),
                ElapsedMilliseconds = result.Took,
                IsValid = result.IsValid
            });
        }
        public static void Initialize()
        {
            ICategoryRepository   catRepository      = (ICategoryRepository)System.Web.Mvc.DependencyResolver.Current.GetService(typeof(ICategoryRepository));
            IAccountRepository    accRepository      = (IAccountRepository)System.Web.Mvc.DependencyResolver.Current.GetService(typeof(IAccountRepository));
            IBoardRepository      boardRepository    = (IBoardRepository)System.Web.Mvc.DependencyResolver.Current.GetService(typeof(IBoardRepository));
            IWorkflowRepository   workflowRepository = (IWorkflowRepository)System.Web.Mvc.DependencyResolver.Current.GetService(typeof(IWorkflowRepository));
            IWorktaskRepository   worktaskRepository = (IWorktaskRepository)System.Web.Mvc.DependencyResolver.Current.GetService(typeof(IWorktaskRepository));
            CategoryService       catService;
            UserPermissionService userService;
            KanbanService         kanbanService;
            WorkflowService       workflowService;
            BoardService          boardService;
            WorktaskService       worktaskService;

            if (CategoryService.GetInstance() == null)
            {
                catService = new CategoryService(catRepository);
            }
            else
            {
                catService = CategoryService.GetInstance();
            }
            if (UserPermissionService.GetInstance() == null)
            {
                userService = new UserPermissionService(accRepository);
            }
            else
            {
                userService = UserPermissionService.GetInstance();
            }
            if (KanbanService.GetInstance() == null)
            {
                kanbanService = new KanbanService(boardRepository, accRepository);
            }
            else
            {
                kanbanService = KanbanService.GetInstance();
            }
            if (WorkflowService.GetInstance() == null)
            {
                workflowService = new WorkflowService(workflowRepository);
            }
            else
            {
                workflowService = WorkflowService.GetInstance();
            }
            if (BoardService.GetInstance() == null)
            {
                boardService = new BoardService(boardRepository);
            }
            else
            {
                boardService = BoardService.GetInstance();
            }
            if (WorktaskService.GetInstance() == null)
            {
                worktaskService = new WorktaskService(worktaskRepository, catRepository);
            }
            else
            {
                worktaskService = WorktaskService.GetInstance();
            }
        }