Ejemplo n.º 1
0
        public async Task <IActionResult> Index([FromQuery] LarsSearchRequestModel request)
        {
            if (request == null)
            {
                return(BadRequest());
            }

            var results = await Task.WhenAll(
                // There's not currently support for multi-select faceted search, so we need to get all the results for the search term before filtering on facets.
                _searchClient.Search(new LarsSearchQuery
            {
                SearchText = request.SearchTerm,
                CertificationEndDateFilter = DateTimeOffset.UtcNow,
                Facets   = new[] { nameof(Lars.AwardOrgCode), nameof(Lars.NotionalNVQLevelv2) },
                PageSize = 0
            }),
                _searchClient.Search(new LarsSearchQuery
            {
                SearchText = request.SearchTerm,
                NotionalNVQLevelv2Filters  = request.NotionalNVQLevelv2Filter,
                AwardOrgCodeFilters        = request.AwardOrgCodeFilter,
                AwardOrgAimRefFilters      = request.AwardOrgAimRefFilter,
                CertificationEndDateFilter = DateTimeOffset.UtcNow,
                Facets     = new[] { nameof(Lars.AwardOrgCode), nameof(Lars.NotionalNVQLevelv2) },
                PageSize   = _larsSearchSettings.ItemsPerPage,
                PageNumber = request.PageNo
            }));

            var unfilteredResult = results[0];
            var result           = results[1];

            var viewModel = new LarsSearchResultModel
            {
                SearchTerm = request.SearchTerm,
                Items      = result.Items.Select(r => r.Record).Select(LarsSearchResultItemModel.FromLars),
                Filters    = new[]
                {
                    new LarsSearchFilterModel
                    {
                        Title = "Qualification level",
                        Items = unfilteredResult.Facets[nameof(Lars.NotionalNVQLevelv2)]
                                .Select((f, i) =>
                                        new LarsSearchFilterItemModel
                        {
                            Id         = $"{nameof(LarsSearchRequestModel.NotionalNVQLevelv2Filter)}-{i}",
                            Name       = nameof(LarsSearchRequestModel.NotionalNVQLevelv2Filter),
                            Text       = LarsSearchFilterItemModel.FormatAwardOrgCodeSearchFilterItemText(f.Key.ToString()),
                            Value      = f.Key.ToString(),
                            Count      = (int)(f.Value ?? 0),
                            IsSelected = request.NotionalNVQLevelv2Filter.Contains(f.Key.ToString())
                        })
                                .OrderBy(f => f.Text).ToArray()
                    },
                    new LarsSearchFilterModel
                    {
                        Title = "Awarding organisation",
                        Items = unfilteredResult.Facets[nameof(Lars.AwardOrgCode)]
                                .Select((f, i) =>
                                        new LarsSearchFilterItemModel
                        {
                            Id         = $"{nameof(LarsSearchRequestModel.AwardOrgCodeFilter)}-{i}",
                            Name       = nameof(LarsSearchRequestModel.AwardOrgCodeFilter),
                            Text       = f.Key.ToString(),
                            Value      = f.Key.ToString(),
                            Count      = (int)(f.Value ?? 0),
                            IsSelected = request.AwardOrgCodeFilter.Contains(f.Key.ToString())
                        })
                                .OrderBy(f => f.Text).ToArray()
                    }
                },
                TotalCount    = (int)(result.TotalCount ?? 0),
                PageNumber    = request.PageNo,
                ItemsPerPage  = _larsSearchSettings.ItemsPerPage,
                PageParamName = _larsSearchSettings.PageParamName,
                Url           = Request.GetDisplayUrl()
            };

            return(ViewComponent(nameof(LarsSearchResult), viewModel));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ZCodeNotKnown([FromQuery] ZCodeNotKnownRequestModel request)
        {
            if (request == null)
            {
                return(BadRequest());
            }

            RemoveSessionVariables();

            var result = await _searchClient.Search(new LarsSearchQuery
            {
                SearchText   = "Z", // Wildcard is applied automatically
                SearchFields = new[] { nameof(Lars.LearnAimRef) },
                NotionalNVQLevelv2Filters     = request.NotionalNVQLevelv2Filter,
                AwardOrgAimRefFilters         = request.AwardOrgAimRefFilter,
                SectorSubjectAreaTier1Filters = !string.IsNullOrWhiteSpace(request.Level1Id) ? new[] { request.Level1Id } : null,
                SectorSubjectAreaTier2Filters = !string.IsNullOrWhiteSpace(request.Level2Id) ? new[] { request.Level2Id } : null,
                CertificationEndDateFilter    = DateTimeOffset.UtcNow,
                Facets     = new[] { nameof(Lars.NotionalNVQLevelv2), nameof(Lars.AwardOrgAimRef) },
                PageSize   = _larsSearchSettings.ItemsPerPage,
                PageNumber = request.PageNo
            });

            var viewModel = new ZCodeSearchResultModel
            {
                Level1Id = request.Level1Id,
                Level2Id = request.Level2Id,
                Items    = result.Items.Select(r => r.Record).Select(ZCodeSearchResultItemModel.FromLars),
                Filters  = new[]
                {
                    new LarsSearchFilterModel
                    {
                        Title = "Level",
                        Items = result.Facets[nameof(Lars.NotionalNVQLevelv2)]
                                .Select((f, i) =>
                                        new LarsSearchFilterItemModel
                        {
                            Id         = $"{nameof(LarsSearchRequestModel.NotionalNVQLevelv2Filter)}-{i}",
                            Name       = nameof(LarsSearchRequestModel.NotionalNVQLevelv2Filter),
                            Text       = LarsSearchFilterItemModel.FormatAwardOrgCodeSearchFilterItemText(f.Key.ToString()),
                            Value      = f.Key.ToString(),
                            Count      = (int)(f.Value ?? 0),
                            IsSelected = request.NotionalNVQLevelv2Filter.Contains(f.Key.ToString())
                        })
                                .OrderBy(f => f.Text).ToArray()
                    },
                    new LarsSearchFilterModel
                    {
                        Title = "Category",
                        Items = result.Facets[nameof(Lars.AwardOrgAimRef)]
                                .Where(f => Categories.AllCategories.ContainsKey(f.Key.ToString()))
                                .Select((f, i) =>
                                        new LarsSearchFilterItemModel
                        {
                            Id         = $"{nameof(LarsSearchRequestModel.AwardOrgAimRefFilter)}-{i}",
                            Name       = nameof(LarsSearchRequestModel.AwardOrgAimRefFilter),
                            Text       = Categories.AllCategories[f.Key.ToString()],
                            Value      = f.Key.ToString(),
                            Count      = (int)(f.Value ?? 0),
                            IsSelected = request.AwardOrgAimRefFilter.Contains(f.Key.ToString())
                        })
                                .OrderBy(f => f.Text).ToArray()
                    }
                },
                TotalCount    = (int)(result.TotalCount ?? 0),
                CurrentPage   = request.PageNo,
                ItemsPerPage  = _larsSearchSettings.ItemsPerPage,
                PageParamName = _larsSearchSettings.PageParamName,
                Url           = Request.GetDisplayUrl()
            };

            return(ViewComponent(nameof(ZCodeSearchResult), viewModel));
        }