public async Task <ActionResult> Index(Find.Cms.Models.Pages.LocationListPage currentPage) { await _trackingService.PageViewed(HttpContext, currentPage); var query = SearchClient.Instance.Search <Find.Cms.Models.Pages.LocationItemPage>() .PublishedInCurrentLanguage() .FilterOnReadAccess(); if (currentPage.FilterArea != null) { foreach (var filterBlock in currentPage.FilterArea.FilteredItems) { var b = _contentLoader.Get <BlockData>(filterBlock.ContentLink) as IFilterBlock; if (b != null) { query = b.AddFilter(query); } } foreach (var filterBlock in currentPage.FilterArea.FilteredItems) { var b = _contentLoader.Get <BlockData>(filterBlock.ContentLink) as IFilterBlock; if (b != null) { query = b.ApplyFilter(query, Request.QueryString); } } } var locations = query.OrderBy(x => x.PageName) .Take(500) .StaticallyCacheFor(new System.TimeSpan(0, 1, 0)).GetContentResult(); var model = new LocationListViewModel(currentPage) { Locations = locations, MapCenter = GetMapCenter(), UserLocation = GeoPosition.GetUsersLocation(), QueryString = Request.QueryString }; return(View(model)); }
public ITypeSearch <LocationItemPage> AddFilter(ITypeSearch <LocationItemPage> query) { return(query.GeoDistanceFacetFor(x => x.Coordinates, GeoPosition.GetUsersLocation().ToFindLocation(), new NumericRange { From = 0, To = 1000 }, new NumericRange { From = 1000, To = 2500 }, new NumericRange { From = 2500, To = 5000 }, new NumericRange { From = 5000, To = 10000 }, new NumericRange { From = 10000, To = 25000 })); }
public ITypeSearch <LocationItemPage> ApplyFilter(ITypeSearch <LocationItemPage> query, NameValueCollection filters) { var filterString = filters["d"]; if (!string.IsNullOrWhiteSpace(filterString)) { var stringDistances = filterString.Split(',').ToList(); if (stringDistances.Any()) { var userLocation = GeoPosition.GetUsersLocation().ToFindLocation(); var distances = ParseDistances(stringDistances); var distancesFilter = SearchClient.Instance.BuildFilter <LocationItemPage>(); distancesFilter = distances.Aggregate(distancesFilter, (current, distance) => current.Or(x => x.Coordinates.WithinDistanceFrom( new GeoLocation(userLocation.Latitude, userLocation.Longitude), ((int)distance.From.Value).Kilometers(), ((int)distance.To.Value).Kilometers()))); query = query.Filter(x => distancesFilter); } } return(query); }