-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.go
36 lines (31 loc) · 1.06 KB
/
search.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package logic
import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
)
const searchQuery = "@actors:{Keanu Reeves} @genres:{action} @rating:[7.0 +inf] @year:[1995 2005]"
func SearchBestMatrixMovies(ctx context.Context, redisClient *redis.Client) {
searchResult := redisClient.FTSearchWithArgs(ctx, IndexName, searchQuery, &redis.FTSearchOptions{
Return: []redis.FTSearchReturn{
{FieldName: "title", As: "title"},
{FieldName: "year", As: "year"},
{FieldName: "rating", As: "rating"},
},
})
if searchResult.RawVal() != nil {
rawResults := searchResult.RawVal().(map[interface{}]interface{})
var movieTitles []string
if rawResults["total_results"].(int64) > 0 {
results := rawResults["results"].([]interface{})
for _, result := range results {
movie := result.(map[interface{}]interface{})["extra_attributes"].(map[interface{}]interface{})
movieTitles = append(movieTitles, movie["title"].(string))
}
}
fmt.Println("🟥 Document search results:")
for _, title := range movieTitles {
fmt.Printf(" ✅ %s \n", title)
}
}
}