Added search index
This commit is contained in:
56
jobs/search-index/main.go
Normal file
56
jobs/search-index/main.go
Normal file
@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
)
|
||||
|
||||
func main() {
|
||||
aero.Parallel(updateAnimeIndex, updateUserIndex)
|
||||
}
|
||||
|
||||
func updateAnimeIndex() {
|
||||
animeSearchIndex := arn.NewSearchIndex()
|
||||
|
||||
// Anime
|
||||
animeStream, err := arn.AllAnime()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for anime := range animeStream {
|
||||
animeSearchIndex.TextToID[strings.ToLower(anime.Title.Canonical)] = anime.ID
|
||||
}
|
||||
|
||||
// Save in database
|
||||
err = arn.DB.Set("SearchIndex", "Anime", animeSearchIndex)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func updateUserIndex() {
|
||||
userSearchIndex := arn.NewSearchIndex()
|
||||
|
||||
// Users
|
||||
userStream, err := arn.AllUsers()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for user := range userStream {
|
||||
userSearchIndex.TextToID[strings.ToLower(user.Nick)] = user.ID
|
||||
}
|
||||
|
||||
// Save in database
|
||||
err = arn.DB.Set("SearchIndex", "User", userSearchIndex)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user