-
-
Save JohannesRudolph/64320e23b70e5a625b9e to your computer and use it in GitHub Desktop.
Weird RavenDb Spatial query behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public void WithinRadiusOf_NamedSpatialField() | |
{ | |
Session.Advanced.DocumentStore.ExecuteIndex( new NamedSpatialFieldIndex() ); | |
var obj = new ClassWithLocation() | |
{ | |
Id = "obj/1", | |
Location = new Location( 10.0, 11.0 ) | |
}; | |
Session.Store( obj ); | |
Session.SaveChanges(); | |
var namedLuceneQuery = Session.Advanced | |
.LuceneQuery<ClassWithLocation, NamedSpatialFieldIndex>() | |
.WithinRadiusOf( "Location", 1.0, 10.0, 11.0 ) | |
.WaitForNonStaleResults() | |
.ToList(); | |
Assert.Single( namedLuceneQuery ); | |
var linqQueryWithSpatial = Session.Query<ClassWithLocation, NamedSpatialFieldIndex>() | |
.Spatial( x => x.Location, x => x.WithinRadiusOf( 1.0, 10.0, 11.0 ) ) | |
.Customize( x => x.WaitForNonStaleResults() ) | |
.ToList(); | |
Assert.Empty( linqQueryWithSpatial ); // for some reason this doesn't work | |
var linqQueryWithCustomize = Session.Query<ClassWithLocation, NamedSpatialFieldIndex>() | |
.Customize( x => x.WithinRadiusOf( "Location", 1.0, 10.0, 11.0 ) ) | |
.Customize( x => x.WaitForNonStaleResults() ) | |
.ToList(); | |
Assert.Single( linqQueryWithCustomize ); // this works | |
} | |
class ClassWithLocation : IAggregateRoot | |
{ | |
public string Id { get; set; } | |
public Location Location { get; set; } | |
} | |
class ClassWithLocationReduceResult | |
{ | |
public string Id { get; set; } | |
public Location Location { get; set; } | |
} | |
class NamedSpatialFieldIndex : AbstractIndexCreationTask<ClassWithLocation, ClassWithLocationReduceResult> | |
{ | |
public NamedSpatialFieldIndex() | |
{ | |
Map = docs => from d in docs | |
select new ClassWithLocationReduceResult() | |
{ | |
Id = d.Id, | |
Location = (Location)SpatialGenerate( "Location", d.Location.Latitude, d.Location.Longitutde ) | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment