mirror of
https://github.com/thomiceli/opengist.git
synced 2025-06-19 16:37:13 +02:00
Add Meilisearch indexer (#444)
This commit is contained in:
@ -179,12 +179,6 @@ func Search(ctx *context.Context) error {
|
||||
currentUserId = 0
|
||||
}
|
||||
|
||||
var visibleGistsIds []uint
|
||||
visibleGistsIds, err = db.GetAllGistsVisibleByUser(currentUserId)
|
||||
if err != nil {
|
||||
return ctx.ErrorRes(500, "Error fetching gists", err)
|
||||
}
|
||||
|
||||
gistsIds, nbHits, langs, err := index.SearchGists(content, index.SearchGistMetadata{
|
||||
Username: meta["user"],
|
||||
Title: meta["title"],
|
||||
@ -192,7 +186,7 @@ func Search(ctx *context.Context) error {
|
||||
Extension: meta["extension"],
|
||||
Language: meta["language"],
|
||||
Topic: meta["topic"],
|
||||
}, visibleGistsIds, pageInt)
|
||||
}, currentUserId, pageInt)
|
||||
if err != nil {
|
||||
return ctx.ErrorRes(500, "Error searching gists", err)
|
||||
}
|
||||
|
@ -70,6 +70,8 @@ func EditVisibility(ctx *context.Context) error {
|
||||
return ctx.ErrorRes(500, "Error updating this gist", err)
|
||||
}
|
||||
|
||||
gist.AddInIndex()
|
||||
|
||||
ctx.AddFlash(ctx.Tr("flash.gist.visibility-changed"), "success")
|
||||
return ctx.RedirectTo("/" + gist.User.Username + "/" + gist.Identifier())
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ func (s *Server) setFuncMap() {
|
||||
|
||||
return strings.TrimSpace(resultBuilder.String())
|
||||
},
|
||||
"indexEnabled": index.Enabled,
|
||||
"indexEnabled": index.IndexEnabled,
|
||||
"isUrl": func(s string) bool {
|
||||
_, err := url.ParseRequestURI(s)
|
||||
return err == nil
|
||||
|
@ -98,7 +98,7 @@ func (s *Server) registerRoutes() {
|
||||
|
||||
r.GET("/all", gist.AllGists, checkRequireLogin, setAllGistsMode("all"))
|
||||
|
||||
if index.Enabled() {
|
||||
if index.IndexEnabled() {
|
||||
r.GET("/search", gist.Search, checkRequireLogin)
|
||||
} else {
|
||||
r.GET("/search", gist.AllGists, checkRequireLogin, setAllGistsMode("search"))
|
||||
|
@ -151,7 +151,7 @@ func Setup(t *testing.T) *TestServer {
|
||||
|
||||
git.ReposDirectory = filepath.Join("tests")
|
||||
|
||||
config.C.IndexEnabled = false
|
||||
config.C.Index = ""
|
||||
config.C.LogLevel = "error"
|
||||
config.InitLog()
|
||||
|
||||
|
Reference in New Issue
Block a user