Esempio n. 1
0
        public SearchResponse Search(string platform, int?organizationId, int?userId, SearchRequest request)
        {
            var result = new SearchResponse {
                Request = request
            };

            try
            {
                using (new RequestTimer(result))
                {
                    _searchRequestValidator.Validate(platform, organizationId, request);
                    var searchResult = _searchService.Search(platform, request);

                    result.Data    = searchResult.Data;
                    result.Summary = searchResult.Summary;

                    if (request.DebugMode)
                    {
                        result.DebugInfo = searchResult.DebugInfo;
                    }

                    result.Error = searchResult.Error;
                }
            }
            catch (Exception ex)
            {
                result.Error = new ResponseError().Load(ex);
                _logger.LogException(ex);
            }
            return(result);
        }
        public async Task <PublicSearchResult> SearchAsync(SearchRequest request, string entityType, CancellationToken cancellationToken)
        {
            var validationResult = _searchRequestValidator.Validate(request);

            if (!validationResult.IsValid)
            {
                throw new InvalidRequestException("Search request is invalid", validationResult.ValidationErrors);
            }

            if (!request.PointInTime.HasValue)
            {
                request.PointInTime = DateTime.UtcNow;
            }

            var searchResult = await _repository.SearchAsync(request, entityType, request.PointInTime.Value, cancellationToken);

            return(new PublicSearchResult
            {
                Results = searchResult.Results
                          .Select(registeredEntity =>
                                  new PublicSearchResultItem
                {
                    Entities = registeredEntity.Entities
                               .Select(entity =>
                                       new EntityPointer
                    {
                        SourceSystemName = entity.SourceSystemName,
                        SourceSystemId = entity.SourceSystemId,
                    })
                               .ToArray(),
                    IndexedData = new Entity
                    {
                        Name = GetFirstNotNullValue(registeredEntity.Entities, x => x.Name),
                        Type = GetFirstNotNullValue(registeredEntity.Entities, x => x.Type),
                        SubType = GetFirstNotNullValue(registeredEntity.Entities, x => x.SubType),
                        Status = GetFirstNotNullValue(registeredEntity.Entities, x => x.Status),
                        OpenDate = GetFirstNotNullValue(registeredEntity.Entities, x => x.OpenDate),
                        CloseDate = GetFirstNotNullValue(registeredEntity.Entities, x => x.CloseDate),
                        Urn = GetFirstNotNullValue(registeredEntity.Entities, x => x.Urn),
                        Ukprn = GetFirstNotNullValue(registeredEntity.Entities, x => x.Ukprn),
                        Uprn = GetFirstNotNullValue(registeredEntity.Entities, x => x.Uprn),
                        CompaniesHouseNumber = GetFirstNotNullValue(registeredEntity.Entities, x => x.CompaniesHouseNumber),
                        CharitiesCommissionNumber = GetFirstNotNullValue(registeredEntity.Entities, x => x.CharitiesCommissionNumber),
                        AcademyTrustCode = GetFirstNotNullValue(registeredEntity.Entities, x => x.AcademyTrustCode),
                        DfeNumber = GetFirstNotNullValue(registeredEntity.Entities, x => x.DfeNumber),
                        LocalAuthorityCode = GetFirstNotNullValue(registeredEntity.Entities, x => x.LocalAuthorityCode),
                        ManagementGroupType = GetFirstNotNullValue(registeredEntity.Entities, x => x.ManagementGroupType),
                        ManagementGroupId = GetFirstNotNullValue(registeredEntity.Entities, x => x.ManagementGroupId),
                        ManagementGroupCode = GetFirstNotNullValue(registeredEntity.Entities, x => x.ManagementGroupCode),
                        ManagementGroupUkprn = GetFirstNotNullValue(registeredEntity.Entities, x => x.ManagementGroupUkprn),
                        ManagementGroupCompaniesHouseNumber = GetFirstNotNullValue(registeredEntity.Entities, x => x.ManagementGroupCompaniesHouseNumber),
                    },
                })
                          .ToArray(),
                Skipped = request.Skip,
                Taken = searchResult.Results.Length,
                TotalNumberOfRecords = searchResult.TotalNumberOfRecords,
            });
        }
Esempio n. 3
0
        public async Task <IActionResult> Get([FromQuery] SearchRequest request)
        {
            var message = _validator.Validate(request);

            if (message != null)
            {
                return(BadRequest(message));
            }

            var response = await _searchService.Search(request.Keywords, request.URL);

            return(Ok(response));
        }