Skip to content

Instantly share code, notes, and snippets.

@jasondentler
Created December 14, 2012 19:53
Show Gist options
  • Save jasondentler/4288124 to your computer and use it in GitHub Desktop.
Save jasondentler/4288124 to your computer and use it in GitHub Desktop.
Crazy spatial index
{
"Token": "/new-homes/fl/tampa/lithia/fishhawk-garden-district-manors",
"CanonicalUrl": null,
"NavigationUrl": null,
"Title": "FishHawk Ranch Garden District Manors Home Builder, Homes",
"ContentBlock": "<p>David Weekley Homes is now building in FishHawk Ranch Garden District Manors! In this Hillsborough community, you&rsquo;ll enjoy David Weekley homes on 85&rsquo; homesites that have it all &ndash; luxurious amenities and the latest <a href=\"/energy-saver-homes/fl/tampa\">energy-efficient building techniques</a> within a distinct urban-living area. In addition, you&rsquo;ll find many stunning architectural details like front porches and alley garages and amenities the whole family will enjoy. Here, you&rsquo;ll also have access to:</p>\n<ul class=\"show-bullets\">\n<li>Town center with shopping</li>\n<li>Walking trails and greenbelts</li>\n<li>Top-rated schools within community</li>\n<li>Aquatic center, parks and clubhouse</li>\n<li>Lighted tennis and basketball courts</li>\n<li>Easy Access to MacDill Air Force Base</li>\n<li>Palmetto Club</li>\n</ul>",
"MetaKeywords": null,
"MetaDescription": "The Lithia, FL community of FishHawk Ranch Garden District Manors features David Weekley EnergySaver™ Homes on large 85’ Homesites. Find yours today!",
"MetaPhrases": null,
"Index": false,
"MarketId": "markets/45",
"SEOCopy": "",
"CallForPricing": false,
"HidePlans": false,
"Grouping": null,
"MapCenter": {
"Latitude": 27.8524734,
"Longitude": -82.2095869,
"Zoom": 0,
"Icon": null
},
"CommunityEntrance": {
"Latitude": 27.8524734,
"Longitude": -82.2095869,
"Zoom": 0,
"Icon": null
},
"SalesOffice": {
"OfficeType": "Sales",
"Address": {
"Line1": "16315 Bayberry View Dr.",
"Line2": null,
"City": "Lithia",
"StateAbbreviation": "FL",
"ZipCode": "33547",
"Lines": [
"16315 Bayberry View Dr.",
"Lithia, FL 33547"
]
},
"MapPoint": {
"Latitude": 27.8524734,
"Longitude": -82.2095869,
"Zoom": 0,
"Icon": null
},
"Hours": []
},
"CommunityType": "Normal",
"Geolocation": "All",
"Name": "FishHawk Garden District Manors",
"CommunityStatus": "Active",
"Amenities": null,
"BasePrice": 400990,
"MinSqFootage": 2831,
"MaxSqFootage": 3568,
"FloorPlanCount": 3,
"ShowcaseCount": 4,
"City": {
"Id": "cities/2",
"Token": "/new-homes/fl/tampa/lithia",
"Name": "Lithia",
"StateAbbreviation": "FL",
"Title": "Lithia FL New Homes | Lithia Home Builder ",
"Market": {
"Id": "markets/45",
"Token": "/new-homes/fl/tampa",
"Name": "Tampa",
"StateAbbreviation": "FL",
"Title": "Tampa, FL"
}
},
"SchoolIds": [
"schools/4334",
"schools/4928",
"schools/5195"
],
"Media": [
{
"Url": "/media/Slideshow/45d04eb6-b187-4675-b8b8-fd3054d93e7d.jpg",
"Caption": "The Denison"
},
{
"Url": "/media/Slideshow/2fcca5c7-1c3f-4ac0-acd3-967f43aace09.jpg",
"Caption": "Pool"
},
{
"Url": "/media/Slideshow/c51fe036-78d9-4d3b-8d7c-5e1a13afd0a4.jpg",
"Caption": "path"
}
],
"SmallGoogleMapOverride": null,
"LargeGoogleMapOverride": null,
"PlatMap": null,
"VirtualTour": null,
"Features": null,
"TaxInformation": "",
"UtilityInformation": "",
"ActivitiesAndEvents": "",
"CommunityReviews": "",
"SalesConsultantIds": [],
"JdeCode": "38090000"
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DWH.Website.ViewModels;
using Raven.Client.Indexes;
namespace DWH.Website.Indices
{
public class MapMarkersByLocation : AbstractMultiMapIndexCreationTask<MapMarkersByLocation.Result>
{
public class Result : MapMarkerData
{
public object _ { get; set; }
}
public const string TheIndexName = "MapMarkers/ByLocation";
public override string IndexName
{
get { return TheIndexName; }
}
public MapMarkersByLocation()
{
AddMap<Community>(communities => from community in communities
where community.SalesOffice != null &&
community.SalesOffice.MapPoint != null &&
community.SalesOffice.MapPoint.Latitude != 0 &&
community.SalesOffice.MapPoint.Longitude != 0 &&
community.CommunityType == Community.CommunityTypes.Normal
select new
{
Id = community.Id,
Latitude = community.SalesOffice.MapPoint.Latitude,
Longitude = community.SalesOffice.MapPoint.Longitude,
Token = community.Token,
Grouping = community.Grouping,
City = community.City,
Geolocation = community.Geolocation,
Name = community.Name,
BasePrice = community.BasePrice,
MinSqFootage = community.MinSqFootage,
MaxSqFootage = community.MaxSqFootage,
FloorPlanCount = community.FloorPlanCount,
ShowcaseCount = community.ShowcaseCount,
Thumbnail = community.Media.Any() ? community.Media.First().Url : null,
Type = MapMarkerData.MarkerType.Community,
_ = SpatialGenerate(community.SalesOffice.MapPoint.Latitude, community.SalesOffice.MapPoint.Longitude)
});
AddMap<Community>(communities => from community in communities
where community.SalesOffice != null &&
community.SalesOffice.MapPoint != null &&
community.SalesOffice.MapPoint.Latitude != 0 &&
community.SalesOffice.MapPoint.Longitude != 0 &&
community.CommunityType == Community.CommunityTypes.CentralLiving
select new
{
Id = community.Id,
Latitude = community.SalesOffice.MapPoint.Latitude,
Longitude = community.SalesOffice.MapPoint.Longitude,
Token = community.Token,
Grouping = community.Grouping,
City = community.City,
Geolocation = community.Geolocation,
Name = community.Name,
BasePrice = community.BasePrice,
MinSqFootage = community.MinSqFootage,
MaxSqFootage = community.MaxSqFootage,
FloorPlanCount = community.FloorPlanCount,
ShowcaseCount = community.ShowcaseCount,
Thumbnail = community.Media.Any() ? community.Media.First().Url : null,
Type = MapMarkerData.MarkerType.CentralLiving,
_ = SpatialGenerate(community.SalesOffice.MapPoint.Latitude, community.SalesOffice.MapPoint.Longitude)
});
AddMap<Community>(communities => from community in communities
where community.SalesOffice != null &&
community.SalesOffice.MapPoint != null &&
community.SalesOffice.MapPoint.Latitude != 0 &&
community.SalesOffice.MapPoint.Longitude != 0 &&
community.CommunityType == Community.CommunityTypes.BOYL
select new
{
Id = community.Id,
Latitude = community.SalesOffice.MapPoint.Latitude,
Longitude = community.SalesOffice.MapPoint.Longitude,
Token = community.Token,
Grouping = community.Grouping,
City = community.City,
Geolocation = community.Geolocation,
Name = community.Name,
BasePrice = community.BasePrice,
MinSqFootage = community.MinSqFootage,
MaxSqFootage = community.MaxSqFootage,
FloorPlanCount = community.FloorPlanCount,
ShowcaseCount = community.ShowcaseCount,
Thumbnail = community.Media.Any() ? community.Media.First().Url : null,
Type = MapMarkerData.MarkerType.BOYLOffice,
_ = SpatialGenerate(community.SalesOffice.MapPoint.Latitude, community.SalesOffice.MapPoint.Longitude)
});
AddMap<Market>(markets => from market in markets
let office =
market.Offices.FirstOrDefault(
o => o.OfficeType == Office.OfficeTypes.DesignCenter)
where office != null &&
office.MapPoint != null &&
office.MapPoint.Latitude != 0 &&
office.MapPoint.Longitude != 0
select new
{
Id = market.MarketId,
Latitude = office.MapPoint.Latitude,
Longitude = office.MapPoint.Longitude,
market.Token,
Grouping = string.Empty,
City = (object) null, // Type doesn't matter once it's on the server
Geolocation = Community.Geolocations.All,
Name = market.Name + " Design Center",
BasePrice = 0,
MinSqFootage = 0,
MaxSqFootage = 0,
FloorPlanCount = 0,
ShowcaseCount = 0,
Thumbnail = (Uri) null,
Type = MapMarkerData.MarkerType.DesignCenter,
_ = SpatialGenerate(office.MapPoint.Latitude, office.MapPoint.Longitude)
});
AddMap<Market>(markets => from market in markets
let office = market.Offices.FirstOrDefault(o => o.OfficeType == Office.OfficeTypes.Division)
where office != null &&
office.MapPoint != null &&
office.MapPoint.Latitude != 0 &&
office.MapPoint.Longitude != 0
select new
{
Id = market.MarketId,
Latitude = office.MapPoint.Latitude,
Longitude = office.MapPoint.Longitude,
market.Token,
Grouping = string.Empty,
City = (object)null, // Type doesn't matter once it's on the server
Geolocation = Community.Geolocations.All,
Name = market.Name + " Division Office",
BasePrice = 0,
MinSqFootage = 0,
MaxSqFootage = 0,
FloorPlanCount = 0,
ShowcaseCount = 0,
Thumbnail = (Uri) null,
Type = MapMarkerData.MarkerType.NewHomeCenter,
_ = SpatialGenerate(office.MapPoint.Latitude, office.MapPoint.Longitude)
});
Reduce = items => from item in items
group item by item.Id
into y
select new Result()
{
Id = y.Key,
Latitude = y.First().Latitude,
Longitude = y.First().Longitude,
Token = y.First().Token,
Grouping = y.First().Grouping,
City = y.First().City,
Geolocation = y.First().Geolocation,
Name = y.First().Name,
BasePrice = y.First().BasePrice,
MinSqFootage = y.First().MinSqFootage,
MaxSqFootage = y.First().MaxSqFootage,
FloorPlanCount = y.First().FloorPlanCount,
ShowcaseCount = y.First().ShowcaseCount,
Thumbnail = y.First().Thumbnail,
Type = y.First().Type,
_ = y.First()._
};
}
}
}
{
"Id": "communities/290",
"Latitude": "27.8524734",
"Longitude": "-82.2095869",
"Token": "/new-homes/fl/tampa/lithia/fishhawk-garden-district-manors",
"Grouping": null,
"City": {
"Id": "cities/2",
"Token": "/new-homes/fl/tampa/lithia",
"Name": "Lithia",
"StateAbbreviation": "FL",
"Title": "Lithia FL New Homes | Lithia Home Builder ",
"Market": {
"Id": "markets/45",
"Token": "/new-homes/fl/tampa",
"Name": "Tampa",
"StateAbbreviation": "FL",
"Title": "Tampa, FL"
}
},
"Geolocation": "All",
"Name": "FishHawk Garden District Manors",
"BasePrice": "400990",
"MinSqFootage": "2831",
"MaxSqFootage": "3568",
"FloorPlanCount": "3",
"ShowcaseCount": "4",
"Thumbnail": "/media/Slideshow/45d04eb6-b187-4675-b8b8-fd3054d93e7d.jpg",
"Type": "Community",
"_": [
{
"StringValue": null,
"ReaderValue": null,
"TokenStreamValue": {
"Factory": {},
"HasAttributes": true
},
"Boost": 1.0,
"Name": "__spatial",
"IsStored": false,
"IsIndexed": true,
"IsTokenized": true,
"IsTermVectorStored": false,
"IsStoreOffsetWithTermVector": false,
"IsStorePositionWithTermVector": false,
"IsBinary": false,
"BinaryLength": 0,
"BinaryOffset": 0,
"OmitNorms": true,
"OmitTermFreqAndPositions": true,
"IsLazy": false
},
{
"StringValue": "-82.209587 27.852473",
"ReaderValue": null,
"TokenStreamValue": null,
"Boost": 1.0,
"Name": "__spatialShape",
"IsStored": true,
"IsIndexed": false,
"IsTokenized": false,
"IsTermVectorStored": false,
"IsStoreOffsetWithTermVector": false,
"IsStorePositionWithTermVector": false,
"IsBinary": false,
"BinaryLength": 0,
"BinaryOffset": 0,
"OmitNorms": true,
"OmitTermFreqAndPositions": false,
"IsLazy": false
}
]
}
using System;
namespace DWH.Website.ViewModels
{
public class MapMarkerData
{
public enum MarkerType
{
Community,
CentralLiving,
BOYLOffice,
NewHomeCenter,
DesignCenter
}
public string Id { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
public Uri Token { get; set; }
public string Grouping { get; set; }
public CityReference City { get; set; }
public Community.Geolocations Geolocation { get; set; }
public string Name { get; set; }
public int BasePrice { get; set; }
public int MinSqFootage { get; set; }
public int MaxSqFootage { get; set; }
public int FloorPlanCount { get; set; }
public int ShowcaseCount { get; set; }
public Uri Thumbnail { get; set; }
public MarkerType Type { get; set; }
}
}
public IEnumerable<MapMarkerData> GetMapData(MapPoint northeast, MapPoint southwest)
{
// northeast and southwest represent the corners of my map window
// about 110 km apart
var center = Center(northeast, southwest); // Returns a point matching my lat/lng in the index
var radius = DistanceBetween(northeast, southwest) / 2.0; // radius about = 55 km
return _session.Advanced.LuceneQuery<MapMarkerData>(MapMarkersByLocation.TheIndexName)
.WithinRadiusOf(radius, center.Latitude, center.Longitude)
.ToList();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment