public SearchResults <TraineeshipSearchResponse, TraineeshipSearchParameters> FindVacancies(TraineeshipSearchParameters parameters) { var client = _elasticsearchClientFactory.GetElasticClient(); var indexName = _elasticsearchClientFactory.GetIndexNameForType(typeof(TraineeshipSummary)); var documentTypeName = _elasticsearchClientFactory.GetDocumentNameForType(typeof(TraineeshipSummary)); _logger.Debug("Calling legacy vacancy search for DocumentNameForType={0} on IndexName={1}", documentTypeName, indexName); var search = PerformSearch(parameters, client, indexName, documentTypeName); var responses = _vacancySearchMapper.Map <IEnumerable <TraineeshipSummary>, IEnumerable <TraineeshipSearchResponse> >(search.Documents).ToList(); responses.ForEach(r => { var hitMd = search.HitsMetaData.Hits.First(h => h.Id == r.Id.ToString(CultureInfo.InvariantCulture)); if (parameters.Location != null) { if (parameters.SortType == VacancySearchSortType.ClosingDate || parameters.SortType == VacancySearchSortType.Distance || parameters.SortType == VacancySearchSortType.RecentlyAdded) { r.Distance = double.Parse(hitMd.Sorts.Skip(hitMd.Sorts.Count() - 1).First().ToString()); } } r.Score = hitMd.Score; }); _logger.Debug("{0} search results returned", search.Total); var results = new SearchResults <TraineeshipSearchResponse, TraineeshipSearchParameters>(search.Total, responses, null, parameters); return(results); }
public IEnumerable <Address> FindAddress(string postcode) { Condition.Requires(postcode, "postcode").IsNotNullOrWhiteSpace(); _logger.Debug("FindAddress for postcode {0}", postcode); var client = _elasticsearchClientFactory.GetElasticClient(); var indexName = _elasticsearchClientFactory.GetIndexNameForType(typeof(Elastic.Common.Entities.Address)); var documentTypeName = _elasticsearchClientFactory.GetDocumentNameForType(typeof(Elastic.Common.Entities.Address)); var postcodeSearch = postcode.Replace(" ", ""); var search = client.Search <Elastic.Common.Entities.Address>(s => { s.Index(indexName); s.Type(documentTypeName); s.Size(100); s.Query(q => q.MatchPhrase(mpqd => mpqd.OnField(a => a.PostcodeSearch).Query(postcodeSearch))); return(s); }); //TODO: vga: refactor in a new ElasticClient class if (ThereWasAnErrorWhileSearching(search)) { throw search.ConnectionStatus.OriginalException; } var addresses = _mapper .Map <IEnumerable <Elastic.Common.Entities.Address>, IEnumerable <Address> >(search.Documents) .ToList(); SanitiseAddresses(addresses); return(addresses); }
public void SetUp() { _container = new Container(x => { x.AddRegistry <LoggingRegistry>(); x.AddRegistry <ElasticsearchCommonRegistry>(); x.AddRegistry <VacancyIndexerRegistry>(); }); var settings = new ConnectionSettings(_elasticsearchConfiguration.DefaultHost); _elasticClient = new ElasticClient(settings); foreach ( IElasticsearchIndexConfiguration elasticsearchIndexConfiguration in _elasticsearchConfiguration.Indexes) { if (elasticsearchIndexConfiguration.Name.EndsWith("_integration_test")) { _elasticClient.DeleteIndex(i => i.Index(elasticsearchIndexConfiguration.Name)); } } _elasticClient = new ElasticClient(settings); _elasticsearchClientFactory = _container.GetInstance <IElasticsearchClientFactory>(); _vacancyIndexAlias = _elasticsearchClientFactory.GetIndexNameForType(typeof(ApprenticeshipSummary)); }
public SearchResults <ApprenticeshipSearchResponse, ApprenticeshipSearchParameters> FindVacancies(ApprenticeshipSearchParameters parameters) { var client = _elasticsearchClientFactory.GetElasticClient(); var indexName = _elasticsearchClientFactory.GetIndexNameForType(typeof(ApprenticeshipSummary)); var documentTypeName = _elasticsearchClientFactory.GetDocumentNameForType(typeof(ApprenticeshipSummary)); _logger.Debug("Calling legacy vacancy search for DocumentNameForType={0} on IndexName={1}", documentTypeName, indexName); var search = PerformSearch(parameters, client, indexName, documentTypeName); var responses = _vacancySearchMapper.Map <IEnumerable <ApprenticeshipSummary>, IEnumerable <ApprenticeshipSearchResponse> > (search.Documents).ToList(); responses.ForEach(r => { var hitMd = search.HitsMetaData.Hits.First(h => h.Id == r.Id.ToString(CultureInfo.InvariantCulture)); if (parameters.Location != null) { if (parameters.SortType == VacancySearchSortType.ClosingDate || parameters.SortType == VacancySearchSortType.Distance || parameters.SortType == VacancySearchSortType.RecentlyAdded) { r.Distance = double.Parse(hitMd.Sorts.Skip(hitMd.Sorts.Count() - 1).First().ToString()); } else { //if anyone can find a better way to get this value out, feel free! var array = hitMd.Fields.FieldValues <JArray>("distance"); var value = array[0]; r.Distance = double.Parse(value.ToString()); } } r.Score = hitMd.Score; }); _logger.Debug("{0} search results returned", search.Total); var aggregationResults = GetAggregationResultsFrom(search.Aggs); var results = new SearchResults <ApprenticeshipSearchResponse, ApprenticeshipSearchParameters>(search.Total, responses, aggregationResults, parameters); return(results); }
public void Run() { _logger.Info("Getting draft vacancy ids"); var draftVacancyIds = _applicationDiagnosticsRepository.GetDraftApplicationVacancyIds().ToList(); var draftVacancyIdsString = string.Join(", ", draftVacancyIds); _logger.Info("Draft vacancy ids {0}: {1}", draftVacancyIds.Count, draftVacancyIdsString); var client = _elasticsearchClientFactory.GetElasticClient(); var indexName = _elasticsearchClientFactory.GetIndexNameForType(typeof(Elastic.Common.Entities.ApprenticeshipSummary)); _logger.Info("Getting vacancy ids in index"); var searchResponse = client.Search <Elastic.Common.Entities.ApprenticeshipSummary>(s => s .Index(indexName) .Fields("id") .Filter(fc => fc.Ids(draftVacancyIds)) .Size(draftVacancyIds.Count)); var vacancyIdsInIndex = searchResponse.Hits.Select(v => v.Id).ToList(); var vacancyIdsInIndexString = string.Join(", ", vacancyIdsInIndex); _logger.Info("Vacancy ids in index {0}: {1}", vacancyIdsInIndex.Count, vacancyIdsInIndexString); var expiredVacancyIds = draftVacancyIds.Except(vacancyIdsInIndex).ToList(); var expiredVacancyIdsString = string.Join(", ", expiredVacancyIds); _logger.Info("Expired vacancy ids {0}: {1}", expiredVacancyIds.Count, expiredVacancyIdsString); /*var verifiedExpiredVacancyIds = expiredVacancyIds.ToList(); * * Logger.Info("Verifying expired vacancies"); * foreach (var expiredVacancyId in expiredVacancyIds) * { * int vacancyId; * if (int.TryParse(expiredVacancyId, out vacancyId)) * { * var vacancyDetails = _vacancySearchService.GetVacancyDetails(vacancyId); * if (vacancyDetails != null) * { * Logger.Info("Vacancy with id: {0} has not expired and will be removed", vacancyId); * verifiedExpiredVacancyIds.Remove(expiredVacancyId); * } * } * else * { * Logger.Info("Vacancy id: {0} could not be parsed so assume still valid", expiredVacancyId); * verifiedExpiredVacancyIds.Remove(expiredVacancyId); * } * } * * var verifiedExpiredVacancyIdsString = string.Join(", ", verifiedExpiredVacancyIds); * Logger.Info("Verified expired vacancy ids {0}: {1}", verifiedExpiredVacancyIds.Count, verifiedExpiredVacancyIdsString);*/ }
public long GetApprenticeshipsCount() { var client = _elasticsearchClientFactory.GetElasticClient(); var indexName = _elasticsearchClientFactory.GetIndexNameForType(typeof(ApprenticeshipSummary)); var documentTypeName = _elasticsearchClientFactory.GetDocumentNameForType(typeof(ApprenticeshipSummary)); var response = client.Count <ApprenticeshipSummary>(s => { s.Index(indexName); s.Type(documentTypeName); return(s); }); var count = response.Count; return(count); }
private string GetIndexAlias() { return(_elasticsearchClientFactory.GetIndexNameForType(typeof(TDestinationSummary))); }
public void ShouldReturnIndexNamesFromConfigurationForMappedObjectType() { _elasticsearchClientFactory.GetIndexNameForType(typeof(ApprenticeshipSummary)).Should().EndWith("apprenticeships"); _elasticsearchClientFactory.GetIndexNameForType(typeof(TraineeshipSummary)).Should().EndWith("traineeships"); _elasticsearchClientFactory.GetIndexNameForType(typeof(LocationLookup)).Should().EndWith("locations"); }
public SearchResults <ApprenticeshipSearchResponse, ApprenticeshipSearchParameters> FindVacancies(ApprenticeshipSearchParameters parameters) { var indexName = _elasticsearchClientFactory.GetIndexNameForType(typeof(ApprenticeshipSummary)); return(FindVacancies(parameters, indexName)); }