From 9086bd18f61661a25ed874e0d983e3b2f77157ea Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Tue, 10 Dec 2019 17:12:02 +0100 Subject: [PATCH] Search for all words that start with query string Signed-off-by: Michael Mayer --- internal/photoprism/search.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/photoprism/search.go b/internal/photoprism/search.go index 9b640d0bd..3721128f9 100644 --- a/internal/photoprism/search.go +++ b/internal/photoprism/search.go @@ -102,11 +102,12 @@ func (s *Search) Photos(f form.PhotoSearch) (results []PhotoSearchResult, err er } else if f.Query != "" { slugString := slug.Make(f.Query) lowerString := strings.ToLower(f.Query) + likeString := lowerString + "%" if result := s.db.First(&label, "label_slug = ?", slugString); result.Error != nil { log.Infof("search: label \"%s\" not found", f.Query) - q = q.Where("labels.label_slug = ? OR keywords.keyword = ? OR files.file_main_color = ?", slugString, lowerString, lowerString) + q = q.Where("labels.label_slug = ? OR keywords.keyword LIKE ? OR files.file_main_color = ?", slugString, likeString, lowerString) } else { labelIds = append(labelIds, label.ID) @@ -118,7 +119,7 @@ func (s *Search) Photos(f form.PhotoSearch) (results []PhotoSearchResult, err er log.Infof("search: label \"%s\" includes %d categories", label.LabelName, len(labelIds)) - q = q.Where("labels.id IN (?) OR keywords.keyword = ? OR files.file_main_color = ?", labelIds, lowerString, lowerString) + q = q.Where("labels.id IN (?) OR keywords.keyword LIKE ? OR files.file_main_color = ?", labelIds, likeString, lowerString) } }