Ejemplo n.º 1
0
        public async Task <IActionResult> AuthorSearch(AuthorSearchRequestViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var authorSearchRequest = viewModel.AuthorSearchRequest;

            var organizationAlternativeNames = OrganizationProvider.GetAlternativeNames(authorSearchRequest.Organization);

            var possibleOrganizations = new List <string>();

            if (!string.IsNullOrEmpty(authorSearchRequest.Organization))
            {
                possibleOrganizations.Add(authorSearchRequest.Organization);
                possibleOrganizations.AddRange(organizationAlternativeNames);
            }

            var profiles = new List <AuthorSearchResult>(await PageParser.GetProfilesFromAuthorSearch(authorSearchRequest.NameSurname, authorSearchRequest.NumberOfRecords, possibleOrganizations));

            IEnumerable <AuthorSearchResult> orderedProfiles = new List <AuthorSearchResult>();

            if (!string.IsNullOrEmpty(authorSearchRequest.Keywords))
            {
                var correlationProfiles = new Dictionary <AuthorSearchResult, double>();

                var lsa          = new LSA(authorSearchRequest.Keywords, profiles.Select(a => string.Join("; ", a.Publications.Select(p => p.Name))));
                var correlations = new List <CorrelationItem>(lsa.GetCorrelations());
                for (var i = 0; i < profiles.Count(); i++)
                {
                    correlationProfiles.Add(profiles[i], correlations[i].Value);
                }

                var orderedCorrelationProfiles = correlationProfiles.OrderByDescending(k => k.Value).ToDictionary(pair => pair.Key, pair => pair.Value);
                orderedProfiles = orderedCorrelationProfiles.Keys;
            }
            else
            {
                orderedProfiles = profiles.OrderByDescending(p => p.HIndex);
            }

            return(View("AuthorSearchResults", new AuthorSearchResultsViewModel
            {
                Authors = orderedProfiles,
                PublicationActivity = viewModel.PublicationActivity,
                IsNum1 = viewModel.IsNum1,
                IsNum2 = viewModel.IsNum2
            }));
        }