Exemple #1
0
        public async Task <Results <List <ReferenceVm> > > GetAllAsync(int projectId)
        {
            var results = new Results <List <ReferenceVm> >();

            try
            {
                var projectResults = await _getProjectForUserProcessor.GetAsync(projectId);

                if (projectResults.HasProblem)
                {
                    results.Merge(projectResults);
                    return(results);
                }

                foreach (ProjectReference pendingReferences in projectResults.Data.ProjectReferences.Where(pr => pr.IsPending))
                {
                    _queueManager.QueueArticleScrape(pendingReferences.ReferenceId, _scrapeDepth);
                }

                var documents = await _getDocumentProcessor.GetDocumentsAsync(projectResults.Data.ProjectReferences
                                                                              .Select(pr => pr.ReferenceId));

                results.Data = projectResults.Data.ProjectReferences.Join(documents, l => l.ReferenceId, r => r.Id, (l, r) => new ReferenceVm
                {
                    Id        = l.ReferenceId,
                    Title     = r.Title,
                    Abstract  = r.Abstract,
                    IsPending = l.IsPending
                }).ToList();
            }
            catch (System.Exception e)
            {
                results.AddException(new System.Exception("Failed to get your references", e));
            }

            return(results);
        }
        public async Task <Results <SearchResultsVm> > SearchAsync(int projectId, SearchData searchData)
        {
            int offset = Math.Max(searchData.PageNumber, 0) * searchData.ItemsPerPage;

            IReadOnlyList <Document> documents;
            int totalCount;

            try
            {
                var hiddenResults = await GetHiddenResultsAsync(projectId);

                var allResultIds = (await _searchResultsCacheManager.GetSearchResultsAsync(projectId, searchData)).Except(hiddenResults).ToList();

                documents = await _getDocumentProcessor.GetDocumentsAsync(allResultIds.Skip(offset).Take(searchData.ItemsPerPage));

                totalCount = allResultIds.Count;
            }
            catch (Exception e)
            {
                return(new Results <SearchResultsVm> {
                    Exceptions = { e }
                });
            }

            var vm = new SearchResultsVm
            {
                Results = documents.Select(d => new ResultVm
                {
                    Id          = d.Id,
                    Title       = d.Title,
                    PublishDate = d.PublishDate,
                    Conference  = d.PublicationTitle,
                    Abstract    = d.Abstract,
                    AuthorName  = string.Join(", ", d.Authors.Select(a => a.Name)),
                    CiteCount   = d.CiteCount
                })
                          .ToList(),
                NumberOfPages = (int)Math.Ceiling((double)totalCount / searchData.ItemsPerPage)
            };

            return(new Results <SearchResultsVm>
            {
                Data = vm
            });
        }
        public async Task <Results <SearchVm> > LoadAsync(int projectId)
        {
            var results = new Results <SearchVm>
            {
                Data =
                {
                    ProjectId = projectId
                }
            };

            var projectResults = await _getProjectForUserProcessor.GetAsync(projectId);

            if (projectResults.HasProblem)
            {
                results.Merge(projectResults);
                return(results);
            }

            // Add loaded references, then pending
            var loadedDocuments = await _getDocumentProcessor.GetDocumentsAsync(projectResults.Data.ProjectReferences
                                                                                .Where(pr => pr.IsPending == false)
                                                                                .Select(pr => pr.ReferenceId));

            results.Data.References.AddRange(loadedDocuments.Select(d => new ReferenceVm
            {
                Id        = d.Id,
                Title     = d.Title,
                IsPending = false,
                Abstract  = d.Abstract
            }));

            results.Data.References.AddRange(projectResults.Data.ProjectReferences
                                             .Where(pr => pr.IsPending == true)
                                             .Select(pr => new ReferenceVm {
                Id        = pr.ReferenceId,
                IsPending = true
            }));

            // Sort options
            results.Data.DefaultSortOption = SearchSortType.PageRank;
            foreach (SearchSortType sortType in Enum.GetValues(typeof(SearchSortType)))
            {
                results.Data.SortOptions.Add(new DropdownOption <SearchSortType>
                {
                    Text  = sortType.GetDescription(),
                    Value = sortType
                });
            }

            // Search Depth
            results.Data.DefaultSearchDepth = SearchDepth.Medium;
            foreach (SearchDepth searchDepth in Enum.GetValues(typeof(SearchDepth)))
            {
                results.Data.SearchDepths.Add(new DropdownOption <SearchDepth>
                {
                    Text     = searchDepth.GetDescription(),
                    Value    = searchDepth,
                    HelpText = searchDepth.GetHelpText()
                });
            }

            return(results);
        }