using System;
using System.Linq;
using DWH.Website.ViewModels;
using Raven.Abstractions.Indexing;
using Raven.Client.Indexes;
namespace DWH.Website.Indices.Search
{
public class TransformResult
{
public Community Community { get; set; }
public FloorPlan FloorPlan { get; set; }
public Showcase Showcase { get; set; }
}
public class MapResult : TransformResult
{
public string Id { get; set; }
public string MarketId { get; set; }
public string CityId { get; set; }
public Community.Geolocations Geolocation { get; set; }
public string[] SchoolDistricts { get; set; }
public string[] Amenities { get; set; }
public string Name { get; set; }
public int MinPrice { get; set; }
public int MaxPrice { get; set; }
public int MinSquareFootage { get; set; }
public int MaxSquareFootage { get; set; }
public int MinBedrooms { get; set; }
public int MinBathrooms { get; set; }
public bool? MasterBedroomUpstairs { get; set; }
public double MinStories { get; set; }
public double MinGarages { get; set; }
public bool InteractiveFloorPlan { get; set; }
public bool VirtualTour { get; set; }
public bool CloseOutCommunity { get; set; }
public string CommunityName { get; set; }
public string CommunityGrouping { get; set; }
public string CommunityId { get; set; }
public Community.CommunityTypes CommunityType { get; set; }
}public class CommunitySearchIndex : AbstractMultiMapIndexCreationTask<MapResult>
{
public const string TheIndexName = "Communities/Search";
public override string IndexName
{
get { return TheIndexName; }
}
public CommunitySearchIndex()
{
AddMap<FloorPlan>(floorPlans =>
from floorPlan in floorPlans
let community = LoadDocument<Community>(floorPlan.Community.Id)
where MetadataFor(community).Value<string>("Raven-Entity-Name") == "Communities"
let schoolDistricts = community.SchoolIds.Select(id => LoadDocument<School>(id).SchoolDistrictName).ToArray()
select new MapResult
{
Id = floorPlan.Id,
MarketId = floorPlan.Community.City.Market.Id,
CityId = floorPlan.Community.City.Id,
Geolocation = floorPlan.Community.Geolocation,
SchoolDistricts = schoolDistricts,
Amenities = community.Amenities,
MinPrice = floorPlan.BasePrice,
MaxPrice = floorPlan.BasePrice,
MinSquareFootage = floorPlan.SquareFootage.Maximum,
MaxSquareFootage = floorPlan.SquareFootage.Minimum,
MinBedrooms = floorPlan.Bedrooms.Maximum,
MinBathrooms = floorPlan.FullBaths.Maximum,
MasterBedroomUpstairs = floorPlan.MasterBedroomUpstairs,
MinStories = floorPlan.Stories.Maximum,
MinGarages = floorPlan.Garages.Maximum,
InteractiveFloorPlan = floorPlan.InteractiveFloorPlan,
VirtualTour = floorPlan.VirtualTour != null,
CloseOutCommunity = community.CommunityStatus == Community.CommunityStatuses.CloseOut,
Community = community,
CommunityId = community.Id,
CommunityName = community.Name,
CommunityType = community.CommunityType
}
);
AddMap<Showcase>(showcases =>
from showcase in showcases
let community = LoadDocument<Community>(showcase.Community.Id)
where MetadataFor(community).Value<string>("Raven-Entity-Name") == "Communities"
let schoolDistricts = community.SchoolIds.Select(id => LoadDocument<School>(id).SchoolDistrictName).ToArray()
select new MapResult
{
Id = showcase.Id,
MarketId = showcase.Community.City.Market.Id,
CityId = showcase.Community.City.Id,
Geolocation = showcase.Community.Geolocation,
SchoolDistricts = schoolDistricts,
Amenities = community.Amenities,
MinPrice = showcase.Price,
MaxPrice = showcase.Price,
MinSquareFootage = showcase.SquareFootage,
MaxSquareFootage = showcase.SquareFootage,
MinBedrooms = showcase.Bedrooms,
MinBathrooms = showcase.FullBaths,
MasterBedroomUpstairs = showcase.MasterBedroomUpstairs,
MinStories = showcase.Stories,
MinGarages = showcase.Garages,
InteractiveFloorPlan = showcase.InteractiveFloorPlan,
VirtualTour = showcase.VirtualTour != null,
CloseOutCommunity = community.CommunityStatus == Community.CommunityStatuses.CloseOut,
Community = community,
CommunityId = community.Id,
CommunityName = community.Name,
CommunityType = community.CommunityType
}
);
Reduce = results =>
from result in results
group result by result.CommunityId
into g
let firstResult = g.First()
select new
{
Id = firstResult.CommunityId,
MarketId = firstResult.Community.City.Market.Id,
CityId = firstResult.Community.City.Id,
Geolocation = firstResult.Community.Geolocation,
SchoolDistricts = firstResult.SchoolDistricts,
Amenities = firstResult.Amenities,
MinPrice = g.Max(r => r.MinPrice),
MaxPrice = g.Min(r => r.MaxPrice),
MinSquareFootage = g.Max(r => r.MinSquareFootage),
MaxSquareFootage = g.Min(r => r.MaxSquareFootage),
MinBedrooms = g.Max(r => r.MinBedrooms),
MinBathrooms = g.Max(r => r.MinBathrooms),
MasterBedroomUpstairs = g.Select(r => r.MasterBedroomUpstairs),
MinStories = g.Max(r => r.MinStories),
MinGarages = g.Max(r => r.MinGarages),
InteractiveFloorPlan = g.Any(r => r.InteractiveFloorPlan),
VirtualTour = g.Any(r => r.VirtualTour),
CloseOutCommunity = firstResult.CloseOutCommunity,
Community = firstResult.Community,
CommunityId = firstResult.Community.Id,
CommunityName = firstResult.Community.Name,
CommunityType = firstResult.Community.CommunityType
};
Index(r => r.Amenities, FieldIndexing.NotAnalyzed);
Index(r => r.Geolocation, FieldIndexing.NotAnalyzed);
Index(r => r.SchoolDistricts, FieldIndexing.NotAnalyzed);
}
}
}--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Yep.
Oren,
When we need some professional-level support ASAP, how do we reach your team during the day (in the US)?
I think we have things under control now, but management is losing faith in your product, and I'd rather not use NHibernate or EF for the next 5 years because you sleep. :)
- J
That's why I checked the index def before recycling. It was still current.
Not Skype, but yes. I'm sure we can find something to bust through our firewall. Give me 2 hours to get in to the office.
It's intermittent.
Getting settled & booting up now
Oren,