1

I have tried to use redisearch-go library with Geo Field.

I don't understand how to set a Geo Field to the document.

My schema is as below.

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)
}

Help me how to define the geofeild as an interface marked in question marks on below code.

doc.Set("vehicle_id", "vehicle_1").Set("location", ?????????? )
Buddhika
  • 577
  • 2
  • 6
  • 20

1 Answers1

1

@Buddhika the godoc reference of redisearch contains several examples, one of which is a geo one that relates to what you've described.

Here's the example description:

The following example illustrates geospatial search using RediSearch. This examples maps to the Redis vanilla example showcased on https://redis.io/commands/georadius#examples. We'll start by adding two docs ( one for each city ) and then do a georadius search based on a starting point and 2 distinct radius: 1)- First query with 100KM radius centered at long,lat 15,37 that should only output the city named "Catania"; 2)- Second query with 200KM radius centered at long,lat 15,37 that should output the cities named "Palermo" and "Catania";

I believe it should be enough to answer the question. If not, we can always add more examples to the docs. https://pkg.go.dev/github.com/RediSearch/redisearch-go@v1.1.1/redisearch#example-Client.Search