2012-08-30 3 views
1

다음과 같이 결과가 0이됩니다.RavenDB Spatial Queries가 결과를 반환하지 않습니다.

쿼리 코드 :

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(); 

인덱스 번호 :

/// <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()); 
     } 

내가 뭘 잘못하고 있는거야? 이 ;, 내가 session.Store (newRoute을)보고에 사용 해요 ... 아주 간단

감사

코드에서
+0

WithinRadiusOf에 전달할 값은 무엇입니까? –

+0

단위 테스트의 위도/경도에 언급 된 것들 – Jeff

+0

테스트의 목적을 위해 방금 저장 한 동일한 값을 검색하고 있습니다 – Jeff

답변

3

당신이 routeService.Save (newRoute)을 가지고 있어야처럼 보인다; 다음 session.SaveChanges();

당신이 session.SaveChanges()를 호출 할 때까지 데이터베이스에 기록되지 않습니다.

하지만 ravenDB에 변경 사항을 색인 할 시간을 주어야합니다. 나는 "오래되지 않은 결과를 기다리십시오"라는 것을 사용하도록 제안합니다. 그러나 지금 당장은 그 코드를 기억하지 못합니다.

+0

당신이 이겼어 !! 고맙습니다! 추가 된 session.Query () .Customize (x => x.WaitForNonStaleResults()). ToArray(); – Jeff

관련 문제