RavenDB空间搜索始终为空

时间:2019-03-07 16:54:43

标签: c# indexing ravendb spatial

我试图根据纬度和经度查找文档,所以我明白了:

已经存储的示例文档应该被找到:

{
    "UID": "uIwHCBvvAJ",
    "Description": "galletita",
    "Created": "03/01/2019 08:40:18",
    "Active": true,
    "Point": {
        "latitude": -37.7505796,
        "longitude": -57.4275142,
        "distanceFromMe": 0
    },
    "Shape": {
        "s": null,
        "Longitude": null
    }
}

现在这是索引,类和查询:

public class Test_Spatial40 : AbstractIndexCreationTask<Test>
    {
        public Test_Spatial40()
        {
            Map = docs => from spatial in docs
                          select new
                          {
                              Shape = spatial.Shape,
                              Point = spatial.Point,
                              _ = SpatialGenerate("Coordinates", spatial.Point.latitude, spatial.Point.longitude),
                              _2 = SpatialClustering("Clustering", spatial.Point.latitude, spatial.Point.longitude)
                          };

            Spatial(x => x.Shape, options => options.Geography.Default());
            Spatial(x => x.Point, options => options.Cartesian.BoundingBoxIndex());
        }
    }

List<Test> r = session
                        .Query<Test, Test_Spatial40>()
                        .Customize(x => x.SortByDistance())
                        .Spatial(
                            x => x.Shape,
                            criteria => criteria
                                .WithinRadius((int)maxDist, (double)la, (double)lo))
                        .ToList();

from spatial in docs
            select new
            {
                Shape = spatial.Shape,
                Point = spatial.Point,
                _ = SpatialGenerate("Coordinates", spatial.Point.latitude, spatial.Point.longitude),
                _2 = SpatialClustering("Clustering", spatial.Point.latitude, spatial.Point.longitude)
            };

        Spatial(x => x.Shape, options => options.Geography.Default());
        Spatial(x => x.Point, options => options.Cartesian.BoundingBoxIndex()); 

假设向查询传递相同的纬度和经度应该返回结果,但是每次都为空...有什么想法吗?

1 个答案:

答案 0 :(得分:2)

要进行查询,您需要在“形状”字段中输入“纬度”和“经度”。 (如果要按形状查询)。