1

次の結果で0の結果が得られますが、そうではないと思います。

クエリコード:

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

私がここで間違っていることについて何か考えはありますか?それはかなり簡単なはずです...

ありがとう

4

1 に答える 1

3

あなたのコードにはrouteService.Save(newRoute);があります。私はsession.Store(newRoute);を見るのに慣れています。次にsession.SaveChanges();

session.SaveChanges();を呼び出すまで、データベースに書き込まれることはありません。

ただし、ravenDBに変更のインデックスを作成する時間を与える必要があります。「古くない結果を待つ」を使用することをお勧めします。現時点ではそのコードを覚えていませんが、ravendbの古くない結果をグーグルで検索した場合。

于 2012-09-03T01:37:33.513 に答える