【问题标题】:RavenDB Spatial FilterRavenDB 空间过滤器
【发布时间】:2021-01-17 20:36:22
【问题描述】:

帮助了解 RavenDB 查询,我正在使用以下模型来存储和索引空间数据。

public class GeoRecord {
 public string SearchId {get; set;}
 public string Tag {get; set;}
 public double Latitude {get; set;}
 public double Longitude {get; set;}
}


public class GeoRecord_GeoIndex : AbstractIndexCreationTask<GeoRecord>
    {
        public GeoRecord_GeoIndex()
        {
            Map = records => from @record in records
                select new
                {
                    IndexName = "geoIndex",
                    record.SearchId,
                    Coordinates = CreateSpatialField(@record.Latitude, @record.Longitude)
                };
        }
    }

我可以使用空间查询过滤所有 GeoRecord,如下所示:

await session
    .Query<GeoRecord, GeoRecord_GeoIndex>()
    .Spatial("Coordinates", factory => factory.Within(shapeWkt: wkt))
    .ToListAsync();

但是我想通过 SearchId 和坐标进行过滤,我得到了这个解决方案,但是我想了解它是否使用 GeoRecord_GeoIndex 而不是过滤来自 GeoRecord 的结果。

await session.Advanced.AsyncDocumentQuery<GeoRecord, GeoRecord_GeoIndex>()
                .WhereIn("SearchId", activeSearchIds)
                .Intersect()
                .Spatial("Coordinates", criteria => criteria.Within(shapeWkt:wkt))
                .ToListAsync();

【问题讨论】:

    标签: ravendb


    【解决方案1】:

    您正在查询索引GeoRecord_GeoIndex,它是用于过滤的索引。

    静态索引包含:

    1. Map 函数中指定的每个索引字段的索引术语列表,
      (您的索引字段是:IndexName、SearchId 和坐标)
    2. 到相关文档的映射

    在查询时,根据您的查询过滤索引词,并从数据库中获取相关文档

    一些演示链接:
    https://demo.ravendb.net/demos/csharp/static-indexes/map-index#step-3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多