登录
首页 >  Golang >  Go问答

使用Go客户端进行RedisSearch的Geo Field操作

来源:stackoverflow

时间:2024-02-24 17:21:27 285浏览 收藏

有志者,事竟成!如果你在学习Golang,那么本文《使用Go客户端进行RedisSearch的Geo Field操作》,就很适合你!文章讲解的知识点主要包括,若是你对本文感兴趣,或者是想搞懂其中某个知识点,就请你继续往下看吧~

问题内容

我尝试将 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", ?????????? )

解决方案


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

以下是示例描述:

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

理论要掌握,实操不能落!以上关于《使用Go客户端进行RedisSearch的Geo Field操作》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>