RavenDB空间查询不返回结果
下面的结果是0,我不认为应该是这样 查询代码:RavenDB空间查询不返回结果,ravendb,Ravendb,下面的结果是0,我不认为应该是这样 查询代码: var sourceResults = session.Advanced.LuceneQuery<Route>("Routes/BySource") .WithinRadiusOf(5, toMatch.Source.Location.Latitude, toMatch.Source.Location.Longitude) .WhereBetween(r => r.DateTime
var sourceResults = session.Advanced.LuceneQuery<Route>("Routes/BySource")
.WithinRadiusOf(5, toMatch.Source.Location.Latitude, toMatch.Source.Location.Longitude)
.WhereBetween(r => r.DateTime, minDateTime, maxDateTime).ToArray();
知道我做错了什么吗?看起来应该很简单
谢谢在您的代码中有routeService.Save(新路线);,我习惯于看到session.Store(newRoute);然后是session.SaveChanges() 在调用session.SaveChanges()之前,不会将内容写入数据库
但是您需要给ravenDB时间来索引更改。我建议使用“wait for non stale results”(等待非陈旧结果),我现在不记得这方面的代码,但是如果你在谷歌上搜索ravendb non stale results.你要传递给WithinRadiusOf的值是什么?在单元测试的lat/long中提到的那些值出于测试的目的,我正在搜索我刚刚保存的相同值。你赢了!!非常感谢。添加了session.Query().Customize(x=>x.WaitForNonSaleResults()).ToArray();
/// <summary>
/// Index for spatial search by route source.
/// </summary>
public class Routes_BySource : AbstractIndexCreationTask<Route>
{
public Routes_BySource()
{
Map = routes => from r in routes
select new { _ = SpatialIndex.Generate(r.Source.Location.Latitude, r.Source.Location.Longitude) };
}
}
public class Route
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>
/// The id.
/// </value>
public string Id { get; set; }
/// <summary>
/// Gets or sets the source.
/// </summary>
/// <value>
/// From.
/// </value>
public Address Source { get; set; }
/// <summary>
/// Gets or sets destination.
/// </summary>
/// <value>
/// To.
/// </value>
public Address Destination { get; set; }
/// <summary>
/// Gets or sets the id of the user who requested the route.
/// </summary>
/// <value>
/// The user id.
/// </value>
public string UserId { get; set; }
/// <summary>
/// Gets or sets the date time that the request is for.
/// </summary>
/// <value>
/// The date time.
/// </value>
public DateTime DateTime { get; set; }
}
public class Address
{
/// <summary>
/// Gets or sets the name. This is the formatted full name of the address.
/// </summary>
/// <value>
/// The name.
/// </value>
public string Name { get; set; }
/// <summary>
/// Gets or sets the location.
/// </summary>
/// <value>
/// The location.
/// </value>
public Location Location { get; set; }
}
public class Location
{
public double Latitude { get; set; }
public double Longitude { get; set; }
}
using (var session = Common.DocumentStore.OpenSession())
{
var routeService = new RouteService(session);
var newRoute = new Route
{
Id = Guid.NewGuid().ToString(),
DateTime = DateTime.Now,
UserId = "user",
Source = new Address { Name = "101 W. 79th St. NY, NY", Location = new Location { Latitude = 32, Longitude = 72 } },
Destination = new Address { Name = "101 W. 79th St. NY, NY", Location = new Location { Latitude = 32, Longitude = 72 } }
};
routeService.Save(newRoute);
var routes = routeService.Search(newRoute);
Assert.IsTrue(routes.Any());
}