Example #1
0
        public async Task <HttpResponseMessage> GetPeopleBornThisDay(int?pageSize            = 20,
                                                                     int?currentPage         = 1,
                                                                     string genderFacet      = "",
                                                                     string yearFacet        = "",
                                                                     string makerFacet       = "",
                                                                     string jobFacet         = "",
                                                                     string lastInitialFacet = "",
                                                                     string dateTodayFacet   = "")
        {
            try
            {
                var results = await this.azureSearch.GetPeopleBornThisDay(
                    (pageSize == null)? 20 : (int)pageSize,
                    (currentPage == null)? 1 : (int)currentPage,
                    (genderFacet == null)? "" : genderFacet,
                    (yearFacet == null)? "" : yearFacet,
                    (makerFacet == null)? "" : makerFacet,
                    (jobFacet == null)? "" : jobFacet,
                    (lastInitialFacet == null)? "" : lastInitialFacet,
                    (dateTodayFacet == null)? "" : dateTodayFacet
                    );

                var toc = new BiographyResultSet
                {
                    Facets      = results.Facets,
                    Biographies = results.Results,
                    Count       = results.Count
                };

                var response = Request.CreateResponse(HttpStatusCode.OK, toc, Configuration.Formatters.JsonFormatter);
#if !NO_CACHE_FOR_TESTING_API
                response.Headers.CacheControl = new CacheControlHeaderValue()
                {
                    MaxAge = TimeSpan.FromDays(1), Public = true
                };
#endif
                return(response);
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.InternalServerError,
                    Content = new StringContent(ex.Message)
                });
            }
        }
Example #2
0
        public async Task <HttpResponseMessage> GetBiographySearch(string query               = "",
                                                                   int?pageSize               = 20,
                                                                   int?currentPage            = 1,
                                                                   string searchFields        = "all",
                                                                   string genderFacet         = "",
                                                                   string yearFacet           = "",
                                                                   string makerFacet          = "",
                                                                   string jobFacet            = "",
                                                                   string lastInitialFacet    = "",
                                                                   string sortField           = "",
                                                                   bool?sortInDescendingOrder = false)
        {
            try
            {
                // NOTE: One override: to add in a sortField of "lastName" if the query is empty or just the wildcard * for all results,
                // and the sortField is also not originally specified, with sorting on last name to be in ascending order.
                var sortFieldOverride             = sortField;
                var sortInDescendingOrderOverride = sortInDescendingOrder;
                if ((string.IsNullOrEmpty(query) || query.Trim() == "*") && string.IsNullOrEmpty(sortField))
                {
                    sortFieldOverride             = "lastName";
                    sortInDescendingOrderOverride = false;
                }
#if SCIENCEMAKERSONLY
                var results = await this.azureSearch.BiographySearch(
                    (query == null)? "" : query,
                    (pageSize == null)? 20 : (int)pageSize,
                    (currentPage == null)? 1 : (int)currentPage,
                    (searchFields == null)? "all" : searchFields,
                    (genderFacet == null)? "" : genderFacet,
                    (yearFacet == null)? "" : yearFacet,
                    (makerFacet == null)?WebApiApplication.SCIENCEMAKER_FLAG : WebApiApplication.SCIENCEMAKER_FLAG,
                    (jobFacet == null)? "" : jobFacet,
                    (lastInitialFacet == null)? "" : lastInitialFacet,
                    (sortFieldOverride == null)? "" : sortFieldOverride,
                    (sortInDescendingOrderOverride == null)?false : (bool)sortInDescendingOrderOverride
                    );
#else
                var results = await this.azureSearch.BiographySearch(
                    (query == null)? "" : query,
                    (pageSize == null)? 20 : (int)pageSize,
                    (currentPage == null)? 1 : (int)currentPage,
                    (searchFields == null)? "all" : searchFields,
                    (genderFacet == null)? "" : genderFacet,
                    (yearFacet == null)? "" : yearFacet,
                    (makerFacet == null)? "" : makerFacet,
                    (jobFacet == null)? "" : jobFacet,
                    (lastInitialFacet == null)? "" : lastInitialFacet,
                    (sortFieldOverride == null)? "" : sortFieldOverride,
                    (sortInDescendingOrderOverride == null)?false : (bool)sortInDescendingOrderOverride
                    );
#endif

                var toc = new BiographyResultSet
                {
                    Facets      = results.Facets,
                    Biographies = results.Results,
                    Count       = results.Count
                };

                var response = Request.CreateResponse(HttpStatusCode.OK, toc, Configuration.Formatters.JsonFormatter);
#if !NO_CACHE_FOR_TESTING_API
                response.Headers.CacheControl = new CacheControlHeaderValue()
                {
                    MaxAge = TimeSpan.FromDays(1), Public = true
                };
#endif
                return(response);
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.InternalServerError,
                    Content = new StringContent(ex.Message)
                });
            }
        }