diff --git a/pkg/config/enum.go b/pkg/config/enum.go index 78ff73a..2fa7c4b 100644 --- a/pkg/config/enum.go +++ b/pkg/config/enum.go @@ -68,6 +68,11 @@ var ( "music_movies", "hide_age", } + EssayProfileFields = []string{ + "about_me", + "interests", + "music_movies", + } // Site preference names (stored in ProfileField table) SitePreferenceFields = []string{ diff --git a/pkg/controller/account/search.go b/pkg/controller/account/search.go index c867816..b70162f 100644 --- a/pkg/controller/account/search.go +++ b/pkg/controller/account/search.go @@ -32,7 +32,8 @@ func Search() http.HandlerFunc { // Search filters. var ( isCertified = r.FormValue("certified") - username = r.FormValue("name") // username search + username = r.FormValue("name") // username search + searchTerm = r.FormValue("search") // profile text search gender = r.FormValue("gender") orientation = r.FormValue("orientation") maritalStatus = r.FormValue("marital_status") @@ -48,6 +49,8 @@ func Search() http.HandlerFunc { ageMin, ageMax = ageMax, ageMin } + search := models.ParseSearchString(searchTerm) + // Get current user. currentUser, err := session.CurrentUser(r) if err != nil { @@ -91,6 +94,7 @@ func Search() http.HandlerFunc { Orientation: orientation, MaritalStatus: maritalStatus, HereFor: hereFor, + ProfileText: search, Certified: isCertified == "true", NotCertified: isCertified == "false", InnerCircle: isCertified == "circle", @@ -127,6 +131,7 @@ func Search() http.HandlerFunc { "MaritalStatus": maritalStatus, "HereFor": hereFor, "EmailOrUsername": username, + "Search": searchTerm, "AgeMin": ageMin, "AgeMax": ageMax, "FriendSearch": friendSearch, diff --git a/pkg/models/user.go b/pkg/models/user.go index 9c35f09..bc1ff34 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -258,6 +258,7 @@ type UserSearch struct { Orientation string MaritalStatus string HereFor string + ProfileText *Search Certified bool NotCertified bool InnerCircle bool @@ -364,6 +365,30 @@ func SearchUsers(user *User, search *UserSearch, pager *Pagination) ([]*User, er placeholders = append(placeholders, "here_for", "%"+search.HereFor+"%") } + // Profile text search. + if terms := search.ProfileText; terms != nil { + for _, term := range terms.Includes { + var ilike = "%" + strings.ToLower(term) + "%" + wheres = append(wheres, ` + EXISTS ( + SELECT 1 FROM profile_fields + WHERE user_id = users.id AND name IN ? AND value ILIKE ? + ) + `) + placeholders = append(placeholders, config.EssayProfileFields, ilike) + } + for _, term := range terms.Excludes { + var ilike = "%" + strings.ToLower(term) + "%" + wheres = append(wheres, ` + NOT EXISTS ( + SELECT 1 FROM profile_fields + WHERE user_id = users.id AND name IN ? AND value ILIKE ? + ) + `) + placeholders = append(placeholders, config.EssayProfileFields, ilike) + } + } + // Only admin user can show disabled/banned users. var statuses = []string{} if user.HasAdminScope(config.ScopeUserBan) { diff --git a/pkg/models/user_note.go b/pkg/models/user_note.go index b6c217a..fae125d 100644 --- a/pkg/models/user_note.go +++ b/pkg/models/user_note.go @@ -6,6 +6,7 @@ import ( "strings" "time" + "code.nonshy.com/nonshy/website/pkg/config" "code.nonshy.com/nonshy/website/pkg/log" ) @@ -55,7 +56,7 @@ func CountNotesAboutUser(currentUser *User, user *User) int64 { count int64 ) - if currentUser.IsAdmin { + if currentUser.HasAdminScope(config.ScopeUserNotes) { wheres = append(wheres, "about_user_id = ?") placeholders = append(placeholders, user.ID) } else { diff --git a/web/templates/account/search.html b/web/templates/account/search.html index 14a388d..abef4e4 100644 --- a/web/templates/account/search.html +++ b/web/templates/account/search.html @@ -87,9 +87,9 @@
- +
- @@ -115,15 +115,33 @@
- +
-
+
+
+ + +

+ Tip: you can "quote exact phrases" and + -exclude words (or + -"exclude phrases") from your search. +

+
+
+ +
+
+ +
@@ -151,7 +169,7 @@
-
+
@@ -165,10 +183,7 @@
-
-
- -
+
@@ -182,7 +197,7 @@
-
+
@@ -196,7 +211,10 @@
-
+
+
+ +