2017-06-20 21:27:14 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-06-20 22:34:18 +00:00
|
|
|
"fmt"
|
2017-06-20 21:27:14 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
|
|
|
"github.com/animenotifier/arn"
|
2017-06-20 22:34:18 +00:00
|
|
|
"github.com/fatih/color"
|
2017-06-20 21:27:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-06-20 22:34:18 +00:00
|
|
|
color.Yellow("Updating search index")
|
|
|
|
|
2017-06-20 21:27:14 +00:00
|
|
|
aero.Parallel(updateAnimeIndex, updateUserIndex)
|
2017-06-20 22:34:18 +00:00
|
|
|
|
|
|
|
color.Green("Finished.")
|
2017-06-20 21:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func updateAnimeIndex() {
|
|
|
|
animeSearchIndex := arn.NewSearchIndex()
|
|
|
|
|
|
|
|
// Anime
|
|
|
|
animeStream, err := arn.AllAnime()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for anime := range animeStream {
|
2017-06-20 22:34:18 +00:00
|
|
|
if anime.Title.Canonical != "" {
|
|
|
|
animeSearchIndex.TextToID[strings.ToLower(anime.Title.Canonical)] = anime.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
if anime.Title.Japanese != "" {
|
|
|
|
animeSearchIndex.TextToID[anime.Title.Japanese] = anime.ID
|
|
|
|
}
|
2017-06-20 21:27:14 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 22:34:18 +00:00
|
|
|
fmt.Println(len(animeSearchIndex.TextToID), "anime titles")
|
|
|
|
|
2017-06-20 21:27:14 +00:00
|
|
|
// 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 {
|
2017-06-20 22:34:18 +00:00
|
|
|
if user.IsActive() && user.Nick != "" {
|
|
|
|
userSearchIndex.TextToID[strings.ToLower(user.Nick)] = user.ID
|
|
|
|
}
|
2017-06-20 21:27:14 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 22:34:18 +00:00
|
|
|
fmt.Println(len(userSearchIndex.TextToID), "user names")
|
|
|
|
|
2017-06-20 21:27:14 +00:00
|
|
|
// Save in database
|
|
|
|
err = arn.DB.Set("SearchIndex", "User", userSearchIndex)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|