Skip to content

Instantly share code, notes, and snippets.

@jpv001
Created April 20, 2012 12:43
Show Gist options
  • Save jpv001/2428241 to your computer and use it in GitHub Desktop.
Save jpv001/2428241 to your computer and use it in GitHub Desktop.
Raven Location Spike
public class Cafe
{
public string Id { get; set; }
public string Name { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
}
[TestFixture]
public class AddCafeTest
{
private EmbeddableDocumentStore _store;
private IDocumentSession _session;
//private IList<Cafe> _cafe;
[SetUp]
public void SetUp()
{
_store = new EmbeddableDocumentStore { RunInMemory = true };
_store.Initialize();
_session = _store.OpenSession();
//_cafe = CreateTestData.CafeData();
IndexCreation.CreateIndexes(typeof(AddCafeTest).Assembly, _store);
}
public class Cafe_ByNameAndLocation : AbstractIndexCreationTask<Cafe>
{
public Cafe_ByNameAndLocation()
{
Map = cafes => from cafe in cafes
select new { cafe.Name, _ = SpatialIndex.Generate(cafe.Latitude, cafe.Longitude) };
Index(x => x.Name, FieldIndexing.Analyzed);
}
}
[Test]
public void FindCafeByLocation()
{
Builder<Cafe>.CreateNew()
.With(c => c.Name = "Brother Baba Budan‎")
.With(c => c.Latitude = 38.9690000)
.With(c => c.Longitude = -77.3862000);
var matched = _session.Query<Cafe, Cafe_ByNameAndLocation>()
.Customize(c =>
{
c.WithinRadiusOf(5, latitude: 38.9103000, longitude: -77.3942);
c.WaitForNonStaleResultsAsOfNow();
});
Assert.IsTrue(matched.ToList().Count > 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment