我已经在原型中获得了空间索引和搜索功能,现在我正在尝试将其集成到我们的数据模型稍有不同的正确解决方案中,并且它不会再回来了任何搜索结果。
这些是我的课程
public class SpatialDataModel
{
public int Id { get; set; }
public string Title { get; set; }
public SpatialDataShapeModel SpatialDataShape { get; set; }
}
public class SpatialDataShapeModel
{
public int Id { get; set; }
public DbGeography Shape { get; set; }
}
我已经通过以下两种方式定义了索引:
public class SpatialDatasIndex: AbstractIndexCreationTask<SpatialDataModel>
{
public SpatialDatasIndex()
{
Map = points => from p in points
select new
{
Id = p.Id,
__ = SpatialGenerate("Coords", p.SpatialDataShape.Shape.Latitude, p.SpatialDataShape.Shape.Longitude)
};
}
}
和
public class SpatialDatasIndex: AbstractIndexCreationTask<SpatialDataModel>
{
public SpatialDatasIndex()
{
Map = points => from p in points
select new
{
Id = p.Id,
__ = SpatialGenerate("Coords", p.SpatialDataShape.Shape.AsText())
};
Spatial(x=>x.SpatialDataShape.Shape, o=>o.Geography.Default());
}
}
我在这里使用DbGeography类型并试图摆脱WKT
我试图像这样查询:
using (var session = _documentStore.OpenSession())
{
data = session.Query<SpatialDataModel, SpatialDatasIndex>()
.Customize(x => x.WithinRadiusOf(
fieldName: "Coords",
radius: 1,
latitude: query.Lat,
longitude: query.Lng))
.Take(query.PageSize)
.ToList();
}
任何帮助实现这项工作都会很棒,我无法在Raven网站上找到很多文档,而且我已多次读过这些文档。
更新
JSON
{
"Title": "Test 1",
"SpatialDataShape": {
"Id": 1,
"Shape": {
"Geography": {
"CoordinateSystemId": 4326,
"WellKnownText": "POINT (-0.1217937469482422 51.51461834694225)"
}
}
}
}