From bcc31b714b19ff3817c96c801028e23ace8cc55b Mon Sep 17 00:00:00 2001 From: nickago Date: Tue, 30 Jun 2015 11:56:55 -0700 Subject: Added the ability to have hashtags with dashes in them --- model/utils.go | 2 +- store/sql_post_store.go | 16 ++++++++++++++++ web/react/utils/utils.jsx | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/model/utils.go b/model/utils.go index cc51dfe47..50e427694 100644 --- a/model/utils.go +++ b/model/utils.go @@ -260,7 +260,7 @@ func Etag(parts ...interface{}) string { return etag } -var validHashtag = regexp.MustCompile(`^(#[A-Za-z]+[A-Za-z0-9_]*[A-Za-z0-9])$`) +var validHashtag = regexp.MustCompile(`^(#[A-Za-z]+[A-Za-z0-9_\-]*[A-Za-z0-9])$`) var puncStart = regexp.MustCompile(`^[.,()&$!\[\]{}"':;\\]+`) var puncEnd = regexp.MustCompile(`[.,()&$#!\[\]{}"':;\\]+$`) diff --git a/store/sql_post_store.go b/store/sql_post_store.go index 0ceebc02f..01900023f 100644 --- a/store/sql_post_store.go +++ b/store/sql_post_store.go @@ -356,9 +356,14 @@ func (s SqlPostStore) Search(teamId string, userId string, terms string, isHasht go func() { result := StoreResult{} + termMap := map[string]bool{} + searchType := "Message" if isHashtagSearch { searchType = "Hashtags" + for _,term := range strings.Split(terms, " ") { + termMap[term] = true; + } } // @ has a speical meaning in INNODB FULLTEXT indexes and @@ -394,6 +399,17 @@ func (s SqlPostStore) Search(teamId string, userId string, terms string, isHasht list := &model.PostList{Order: make([]string, 0, len(posts))} for _, p := range posts { + if searchType == "Hashtags" { + exactMatch := false + for _, tag := range strings.Split(p.Hashtags, " ") { + if termMap[tag] { + exactMatch = true + } + } + if !exactMatch { + continue + } + } list.AddPost(p) list.AddOrder(p.Id) } diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index d50a044bc..175fc2922 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -395,8 +395,8 @@ module.exports.textToJsx = function(text, options) { var inner = []; - // Function specific regexes - var hashRegex = /^href="#[^"]+"|(#[A-Za-z]+[A-Za-z0-9_]*[A-Za-z0-9])$/g; + // Function specific regex + var hashRegex = /^href="#[^"]+"|(#[A-Za-z]+[A-Za-z0-9_\-]*[A-Za-z0-9])$/g; var implicitKeywords = {}; var keywordArray = UserStore.getCurrentMentionKeys(); -- cgit v1.2.3-1-g7c22