From 3d6e3ed2e5d6407d20e432e0845fe18d29d7eb72 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 27 May 2017 08:34:09 +0100 Subject: [PATCH] fix search issue Former-commit-id: 6fcb2017aba409c3ec9480f9ea894702eee1be01 [formerly a9c45f3c83ed22a6852e4f7d2fef6155e4a05b26] [formerly bc5dc0641dad6309f33564d8969a42e4dbc37df9 [formerly ac7c4db4e14c17993b038813893acca1234275cb]] Former-commit-id: 4669eafeb0872c2b66183b1c78a2de756b58ca3b [formerly 75efe1c23c13cb34d8aaf1e14b70d9830be16023] Former-commit-id: 5fcc16ffee3df50f302940dab3497be71be7f81f --- README.md | 2 +- handlers/search.go | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) 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 {