Exemplo n.º 1
0
        public ActionResult Search(string searchType, string q = "", int currentPage = 0)
        {
            string businessTitleFacet = "";
            string postingTypeFacet   = "";
            string salaryRangeFacet   = "";
            string sortType           = "";
            double lat         = 40.736224;
            double lon         = -73.99251;
            int    zipCode     = 10001;
            int    maxDistance = 0;

            // If blank search, assume they want to search everything
            if (string.IsNullOrWhiteSpace(q))
            {
                q = "*";
            }

            string maxDistanceLat = string.Empty;
            string maxDistanceLon = string.Empty;

            var response = _jobsSearch.Search(GetIndexNameType(searchType), q, businessTitleFacet, postingTypeFacet, salaryRangeFacet, sortType, lat, lon, currentPage, maxDistance, maxDistanceLat, maxDistanceLon);

            return(new JsonResult
                   (
                       new { results = response.Results, facets = response.Facets, count = (int)response.Count }
                   ));
        }
        public ActionResult Search(string q = "",
                                   string businessTitleFacet = "",
                                   string postingTypeFacet   = "",
                                   string salaryRangeFacet   = "",
                                   string sortType           = "",
                                   double lat      = 40.736224,
                                   double lon      = -73.99251,
                                   int currentPage = 0,
                                   int zipCode     = 10001,
                                   int maxDistance = 0)
        {
            // If blank search, assume they want to search everything
            if (string.IsNullOrWhiteSpace(q))
            {
                q = "*";
            }

            string maxDistanceLat = string.Empty;
            string maxDistanceLon = string.Empty;

            //Do a search of the zip code index to get lat / long of this location
            //Eventually this should be extended to search beyond just zip (i.e. city)
            if (maxDistance > 0)
            {
                var zipReponse = _jobsSearch.SearchZip(zipCode.ToString());
                foreach (var result in zipReponse.Results)
                {
                    var doc = (dynamic)result.Document;
                    maxDistanceLat = Convert.ToString(doc["geo_location"].Latitude);
                    maxDistanceLon = Convert.ToString(doc["geo_location"].Longitude);
                }
            }

            var response = _jobsSearch.Search(q, businessTitleFacet, postingTypeFacet, salaryRangeFacet, sortType, lat, lon, currentPage, maxDistance, maxDistanceLat, maxDistanceLon);

            if (response == null)
            {
                return(new JsonResult());
            }

            return(new JsonResult
            {
                // ***************************************************************************************************************************
                // If you get an error here, make sure to check that you updated the SearchServiceName and SearchServiceApiKey in Web.config
                // ***************************************************************************************************************************

                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new NYCJob()
                {
                    Results = response.Results, Facets = response.Facets, Count = Convert.ToInt32(response.Count)
                }
            });
        }