diff --git a/README.md b/README.md index 2abc2fdb..cf5b0a5d 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ FileManager allows you to search through your files and it has some options. By this are keywords ``` -If you search for that it will look at every file that contains "this", "are" and "keywords" on their name. If you want to search for an exact term, you should surround your search by double quotes: +If you search for that it will look at every file that contains "this", "are" or "keywords" on their name. If you want to search for an exact term, you should surround your search by double quotes: ``` "this is the name" diff --git a/handlers/search.go b/handlers/search.go index 978f18d1..8a1265d3 100644 --- a/handlers/search.go +++ b/handlers/search.go @@ -85,24 +85,29 @@ func Search(w http.ResponseWriter, r *http.Request, c *config.Config, u *config. } path = strings.Replace(path, "\\", "/", -1) + is := false for _, term := range search.Terms { + if is { + break + } + if strings.Contains(path, term) { if !u.Allowed(path) { return nil } - path = strings.TrimPrefix(path, scope) - path = strings.TrimPrefix(path, "/") - - err = conn.WriteMessage(websocket.TextMessage, []byte(path)) - if err != nil { - return err - } + is = true } } - return nil + if !is { + return nil + } + + path = strings.TrimPrefix(path, scope) + path = strings.TrimPrefix(path, "/") + return conn.WriteMessage(websocket.TextMessage, []byte(path)) }) if err != nil {