summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornickago <ngonella@calpoly.edu>2015-08-13 15:52:52 -0700
committernickago <ngonella@calpoly.edu>2015-08-27 08:57:07 -0700
commit824917b029826384129e504e83739fcc55541b4f (patch)
tree007a18731eaa45fe3f32c462b2494f7b810dbb46
parent72fc15ddf370acd836736ff3e3cd33c24c126a17 (diff)
downloadchat-824917b029826384129e504e83739fcc55541b4f.tar.gz
chat-824917b029826384129e504e83739fcc55541b4f.tar.bz2
chat-824917b029826384129e504e83739fcc55541b4f.zip
Added wildcard highlighting and removed redundant whitespace parsing
-rw-r--r--store/sql_post_store.go12
-rw-r--r--web/react/utils/utils.jsx18
2 files changed, 21 insertions, 9 deletions
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index fdff27b82..e30691154 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -419,15 +419,15 @@ func (s SqlPostStore) Search(teamId string, userId string, terms string, isHasht
// cannot escape it so we replace it.
terms = strings.Replace(terms, "@", " ", -1)
- // Parse text for wildcards
- if wildcard, err := regexp.Compile("\\*($| )"); err == nil {
- terms = wildcard.ReplaceAllLiteralString(terms, ":* ")
- terms = strings.Replace(terms, " ", " ", -1)
- }
-
var posts []*model.Post
if utils.Cfg.SqlSettings.DriverName == "postgres" {
+
+ // Parse text for wildcards
+ if wildcard, err := regexp.Compile("\\*($| )"); err == nil {
+ terms = wildcard.ReplaceAllLiteralString(terms, ":* ")
+ }
+
searchQuery := fmt.Sprintf(`SELECT
*
FROM
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index f0cf17446..66740d380 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -457,9 +457,21 @@ module.exports.textToJsx = function(text, options) {
var mentionRegex = /^(?:@)([a-z0-9_]+)$/gi; // looks loop invariant but a weird JS bug needs it to be redefined here
var explicitMention = mentionRegex.exec(trimWord);
- if ((trimWord.toLowerCase().indexOf(searchTerm) > -1 || word.toLowerCase().indexOf(searchTerm) > -1) && searchTerm != '') {
-
- highlightSearchClass = ' search-highlight';
+ if (searchTerm !== '') {
+ let searchWords = searchTerm.split(' ');
+ for (let idx in searchWords) {
+ let searchWord = searchWords[idx];
+ if (searchWord === word.toLowerCase() || searchWord === trimWord.toLowerCase()) {
+ highlightSearchClass = ' search-highlight';
+ break;
+ } else if (searchWord.charAt(searchWord.length - 1) === '*') {
+ let searchWordPrefix = searchWord.slice(0,-1);
+ if (trimWord.toLowerCase().indexOf(searchWordPrefix) > -1 || word.toLowerCase().indexOf(searchWordPrefix) > -1) {
+ highlightSearchClass = ' search-highlight';
+ break;
+ }
+ }
+ }
}
if (explicitMention &&