1

我曾尝试将redisearch-go库与 Geo Field 一起使用。

我不明白如何为文档设置地理字段。

我的架构如下。

schema := redisearch.NewSchema(redisearch.DefaultOptions).
AddField(redisearch.NewTextField("vehicle_id")).
AddField(redisearch.NewGeoField("location"))
    
indexDefinition := redisearch.NewIndexDefinition().AddPrefix("vehicles:")

if err := client.CreateIndexWithIndexDefinition(schema,indexDefinition); err != nil {
    log.Fatal(err)
    println(err)
}

doc := redisearch.NewDocument("veh_1", 1.0)

doc.Set("vehicle_id", "vehicle_1").
Set("location", ?????????? )

if err := c.Index([]redisearch.Document{doc}...); err != nil {
    log.Fatal(err)
    println(err)
}

帮助我如何将 geofeild 定义为下面代码中用问号标记的接口。

doc.Set("vehicle_id", "vehicle_1").Set("location", ?????????? )
4

1 回答 1

1

@Buddhika redisearch 的 godoc 参考包含几个示例,其中一个是与您所描述的内容相关的地理示例。

这是示例描述:

以下示例说明了使用 RediSearch 的地理空间搜索。此示例映射到https://redis.io/commands/georadius#examples上展示的 Redis vanilla 示例。我们将首先添加两个文档(每个城市一个),然后根据一个起点和 2 个不同的半径进行 georadius 搜索:1)- 第一个查询,半径为 100KM,以 long,lat 15,37 为中心,应该只输出名为“卡塔尼亚”的城市;2)- 第二次查询,半径为 200KM,以经纬 15,37 为中心,应输出名为“巴勒莫”和“卡塔尼亚”的城市;

我相信回答这个问题应该足够了。如果没有,我们总是可以在文档中添加更多示例。 https://pkg.go.dev/github.com/RediSearch/redisearch-go@v1.1.1/redisearch#example-Client.Search

于 2021-07-14T19:08:25.177 回答