public ApprenticeshipSearchResults SearchApprenticeships(string keywords, int pageNumber, int pageSize = 20, int sortOrder = 0, IEnumerable <int> selectedLevels = null)
        {
            var formattedKeywords = _queryHelper.FormatKeywords(keywords);

            var searchDescriptor = GetSearchDescriptor(pageNumber, pageSize, formattedKeywords, sortOrder, selectedLevels ?? Enumerable.Empty <int>());

            var results = _elasticsearchCustomClient.Search <ApprenticeshipSearchResultsDocument>(s => searchDescriptor);

            var levelAggregation = BuildLevelAggregationResult(results);

            return(MapToApprenticeshipSearchResults(pageNumber, pageSize, results, levelAggregation));
        }
        private ProviderApprenticeshipLocationSearchResult PerformStandardProviderSearchWithQuery(SearchDescriptor <StandardProviderSearchResultsItem> qryStr, int page, int pageSize)
        {
            var skipAmount = pageSize * (page - 1);

            var results = _elasticsearchCustomClient.Search <StandardProviderSearchResultsItem>(_ => qryStr.Skip(skipAmount).Take(pageSize));

            if (results.ApiCall?.HttpStatusCode != 200)
            {
                return(new ProviderApprenticeshipLocationSearchResult());
            }

            return(MapToProviderApprenticeshipLocationSearchResult(results, page, pageSize));
        }
        private ProviderLocationsSearchResults PerformClosestLocationsQuery <T>(SearchDescriptor <T> qryStr, int page, int pageSize)
            where T : class, IApprenticeshipProviderSearchResultsItem
        {
            var skipAmount = pageSize * (page - 1);

            var results = _elasticsearchCustomClient.Search <T>(_ => qryStr.Skip(skipAmount).Take(pageSize));

            if (results.ApiCall?.HttpStatusCode != 200)
            {
                return(new ProviderLocationsSearchResults());
            }

            return(MapToProviderLocationsSearchResults(results, page, pageSize));
        }
        private List <StandardProviderSearchResultsItem> PerformStandardProviderSearchWithQuery(SearchDescriptor <StandardProviderSearchResultsItem> qryStr, int page)
        {
            var take = _applicationSettings.ApprenticeshipProviderElements;

            var skipAmount = take * (page - 1);

            var results = _elasticsearchCustomClient.Search <StandardProviderSearchResultsItem>(_ => qryStr.Skip(skipAmount).Take(take));

            if (results.ApiCall?.HttpStatusCode != 200)
            {
                return(new List <StandardProviderSearchResultsItem>());
            }

            return(results.Hits.Select(MapToStandardProviderSearchResultsItem).ToList());
        }
        public IEnumerable <LarsStandard> GetListOfStandards()
        {
            var size = GetLarsStandardsSize();

            var standards = _elasticsearchCustomClient
                            .Search <LarsStandard>(s => s
                                                   .Index(_larsSettings.IndexesAlias)
                                                   .Query(q => q
                                                          .Bool(b => b
                                                                .Filter(f => f
                                                                        .Term(t => t.Field("documentType").Value("StandardLars")))))
                                                   .From(0)
                                                   .Size(size));

            return(standards.Documents);
        }
Beispiel #6
0
        public IEnumerable<StandardSummary> GetAllStandards()
        {
            var take = _queryHelper.GetStandardsTotalAmount();

            var searchDescriptor = GetAllStandardsSeachDescriptor(take);

            var results =
                _elasticsearchCustomClient.Search<StandardSearchResultsItem>(s => searchDescriptor);

            if (results.ApiCall.HttpStatusCode != 200)
            {
                throw new ApplicationException($"Failed query all standards");
            }

            var resultList = results.Documents.Select(standardSearchResultsItem => _standardMapping.MapToStandardSummary(standardSearchResultsItem)).ToList();
            return resultList;
        }
Beispiel #7
0
 public ISearchResponse <ProviderNameSearchResult> GetResults(string term, int take, int skip)
 {
     return(_elasticsearchCustomClient.Search <ProviderNameSearchResult>(s => s
                                                                         .Index(_applicationSettings.ProviderIndexAlias)
                                                                         .Skip(skip)
                                                                         .Take(take)
                                                                         .Query(q => q
                                                                                .Bool(b => b
                                                                                      .Filter(IsApiDocument(), IsNotEmployerProvider())
                                                                                      .Must(mu => mu
                                                                                            .QueryString(qs => qs
                                                                                                         .Fields(fs => fs
                                                                                                                 .Field(f => f.ProviderName)
                                                                                                                 .Field(f => f.Aliases))
                                                                                                         .Query(term)))
                                                                                      ))));
 }
Beispiel #8
0
        public IEnumerable <OrganisationSummary> GetAllOrganisations()
        {
            var take = _queryHelper.GetOrganisationsTotalAmount();

            var searchDescriptor = GetAllAssessmentOrgsSearchDescriptor(take);

            var results =
                _elasticsearchCustomClient.Search <OrganisationDocument>(
                    s =>
                    searchDescriptor);

            if (results.ApiCall.HttpStatusCode != 200)
            {
                throw new ApplicationException("Failed query all organisations");
            }

            return(results.Documents.Select(organisation => _assessmentOrgsMapping.MapToOrganisationDto(organisation)).ToList());
        }
        public IEnumerable <FrameworkSummary> GetAllFrameworks()
        {
            var take = _queryHelper.GetFrameworksTotalAmount();

            var searchDescriptor = GetAllFrameworksSearchDescriptor(take);

            var results =
                _elasticsearchCustomClient.Search <FrameworkSearchResultsItem>(s => searchDescriptor);

            if (results.ApiCall.HttpStatusCode != 200)
            {
                throw new ApplicationException($"Failed query all frameworks");
            }

            var resultList = results.Documents.Select(frameworkSearchResultsItem => _frameworkMapping.MapToFrameworkSummary(frameworkSearchResultsItem));

            return(resultList);
        }
Beispiel #10
0
        public int GetOrganisationsTotalAmount()
        {
            var results =
                _elasticsearchCustomClient.Search <OrganisationDocument>(
                    s =>
                    s.Index(_applicationSettings.AssessmentOrgsIndexAlias)
                    .From(0)
                    .Query(q => q.Term("documentType", "organisationdocument")));

            return((int)results.HitsMetadata.Total.Value);
        }
        public IEnumerable <OrganisationSummary> GetAllOrganisations()
        {
            var take    = GetOrganisationsTotalAmount();
            var results =
                _elasticsearchCustomClient.Search <OrganisationDocument>(
                    s =>
                    s.Index(_applicationSettings.AssessmentOrgsIndexAlias)
                    .Type(Types.Parse("organisationdocument"))
                    .From(0)
                    .Sort(sort => sort.Ascending(f => f.EpaOrganisationIdentifier))
                    .Take(take)
                    .MatchAll());

            if (results.ApiCall.HttpStatusCode != 200)
            {
                throw new ApplicationException($"Failed query all organisations");
            }

            return(results.Documents.Select(organisation => _assessmentOrgsMapping.MapToOrganisationDto(organisation)).ToList());
        }
Beispiel #12
0
        public IEnumerable <ProviderSummary> GetAllProviders()
        {
            var take    = GetProvidersTotalAmount();
            var results =
                _elasticsearchCustomClient.Search <Provider>(
                    s =>
                    s.Index(_applicationSettings.ProviderIndexAlias)
                    .Type(Types.Parse(_providerDocumentType))
                    .From(0)
                    .Sort(sort => sort.Ascending(f => f.Ukprn))
                    .Take(take)
                    .MatchAll());

            if (results.ApiCall.HttpStatusCode != 200)
            {
                throw new ApplicationException("Failed query all providers");
            }

            return(results.Documents.Select(provider => _providerMapping.MapToProviderDto(provider)).ToList());
        }
        public PagedSearchResponse <UserSearchModel> FindUsers(string searchText, SearchCategory searchType, int pageSize = 10, int pageNumber = 1)
        {
            if (searchType != SearchCategory.User)
            {
                return(null);
            }

            _indexAliasName = _indexNameCreator.CreateIndexesAliasName(_searchSettings.IndexName, searchType);

            var response = _elasticSearchClient.Search <UserSearchModel>(s => s.Index(_indexAliasName)
                                                                         .Skip(pageSize * GetPage(pageNumber))
                                                                         .Take(pageSize)
                                                                         .Query(q => q
                                                                                .Bool(b => b
                                                                                      .Should(m =>
                                                                                              m.QueryString(qs => qs.Query($"*{searchText}*").AnalyzeWildcard(true).Fields(f => f.Field(fs => fs.FirstNameSearchKeyWord)))
                                                                                              ||
                                                                                              m.QueryString(qs => qs.Query($"*{searchText}*").AnalyzeWildcard(true).Fields(f => f.Field(fs => fs.LastNameSearchKeyWord)))
                                                                                              ||
                                                                                              m.QueryString(qs => qs.Query($"*{searchText}*").AnalyzeWildcard(true).Fields(f => f.Field(fs => fs.EmailSearchKeyWord)))
                                                                                              ||
                                                                                              m.QueryString(qs => qs.Query($"*{searchText}*").AnalyzeWildcard(true).Fields(f => f.Field(fs => fs.NameSearchKeyWord)))
                                                                                              ||
                                                                                              m.Match(mt => mt.Query(searchText).Field(fs => fs.FirstNameSearchKeyWord))
                                                                                              ||
                                                                                              m.Match(mt => mt.Query(searchText).Field(fs => fs.LastNameSearchKeyWord))
                                                                                              ||
                                                                                              m.Match(mt => mt.Query(searchText).Field(fs => fs.NameSearchKeyWord))
                                                                                              ||
                                                                                              m.Match(mt => mt.Query(searchText).Field(fs => fs.EmailSearchKeyWord))
                                                                                              )
                                                                                      ))
                                                                         .Sort(sort => sort.Descending(SortSpecialField.Score))

                                                                         , string.Empty);


            ValidateResponse(response);

            return(GetSearchResponse(pageSize, response));
        }
Beispiel #14
0
        public List <ApprenticeshipSearchResultsItem> SearchApprenticeships(string keywords, int page)
        {
            var takeElements = 20;

            var formattedKeywords = _queryHelper.FormatKeywords(keywords);

            var searchDescriptor = GetSearchDescriptor(page, takeElements, formattedKeywords);

            var results = _elasticsearchCustomClient.Search <ApprenticeshipSearchResultsDocument>(s => searchDescriptor);

            return(results.Documents.Select(_resultDocumentMapping.MapToApprenticeshipSearchResultsItem).ToList());
        }
Beispiel #15
0
        public IEnumerable <ProviderDocument> GetAllProviders()
        {
            var take    = GetProvidersTotalAmount();
            var results =
                _elasticsearchCustomClient.Search <ProviderDocument>(
                    s => s
                    .Index(_applicationSettings.RoatpProviderIndexAlias)
                    .Type(Types.Parse(ProviderDocumentType))
                    .From(0)
                    .Sort(sort => sort.Ascending(f => f.Ukprn))
                    .Take(take)
                    .MatchAll()
                    );

            if (results.ApiCall.HttpStatusCode != 200)
            {
                throw new ApplicationException($"Failed query all providers httpStatusCode was {results.ApiCall.HttpStatusCode}", results.ApiCall.OriginalException);
            }

            return(results.Documents);
        }
Beispiel #16
0
        public IEnumerable <FrameworkSummary> GetAllFrameworks()
        {
            var take = GetFrameworksTotalAmount();

            var results =
                _elasticsearchCustomClient.Search <FrameworkSearchResultsItem>(
                    s =>
                    s.Index(_applicationSettings.ApprenticeshipIndexAlias)
                    .Type(Types.Parse("frameworkdocument"))
                    .From(0)
                    .Sort(sort => sort.Ascending(f => f.FrameworkId))
                    .Take(take)
                    .MatchAll());

            if (results.ApiCall.HttpStatusCode != 200)
            {
                throw new ApplicationException($"Failed query all frameworks");
            }

            var resultList = results.Documents.Select(frameworkSearchResultsItem => _frameworkMapping.MapToFrameworkSummary(frameworkSearchResultsItem)).ToList();

            return(resultList);
        }
        private T GetProvider <T>(Func <QueryContainerDescriptor <T>, QueryContainer> query)
            where T : class
        {
            var results = _elasticsearchCustomClient.Search <T>(s => s.Index(_applicationSettings.ProviderIndexAlias).From(0).Size(1).Query(query));

            if (results.ApiCall.HttpStatusCode != 200)
            {
                throw new ApplicationException($"Failed query standard with provider");
            }

            var document = results.Documents.Any() ? results.Documents.First() : null;

            return(document);
        }
Beispiel #18
0
        public IEnumerable <ProviderSummary> GetAllProviders()
        {
            var take    = _queryHelper.GetProvidersTotalAmount();
            var results =
                _elasticsearchCustomClient.Search <Provider>(
                    s =>
                    s.Index(_applicationSettings.ProviderIndexAlias)
                    .From(0)
                    .Sort(sort => sort.Ascending(f => f.Ukprn))
                    .Take(take)
                    .Query(q => + q.Term("documentType", ProviderIndexType)));

            if (results.ApiCall.HttpStatusCode != 200)
            {
                _applicationLogger.LogWarning($"httpStatusCode was {results.ApiCall.HttpStatusCode}");
                throw new ApplicationException("Failed query all providers");
            }

            return(results.Documents.Select(provider => _providerMapping.MapToProviderDto(provider)).ToList());
        }
Beispiel #19
0
        public List <ProviderSearchResultsItem> SearchProviders(string keywords, int page)
        {
            if (keywords.Length < 3)
            {
                return(new List <ProviderSearchResultsItem>());
            }

            const int takeElements = 20;

            var formattedKeywords = _queryHelper.FormatKeywords(keywords);

            var searchDescriptor = GetSearchDescriptor(page, takeElements, formattedKeywords);

            var results = _elasticsearchCustomClient.Search <ProviderSearchResultsItem>(s => searchDescriptor);

            return(results.Documents.ToList());
        }