diff options
author | Girish S <girish.sonawane@gmail.com> | 2015-10-26 12:25:14 +0530 |
---|---|---|
committer | Girish S <girish.sonawane@gmail.com> | 2015-10-26 12:25:14 +0530 |
commit | 4cfde35256cecab12d317e0d829769143f4df2d0 (patch) | |
tree | a80b99e8cbe4bb1fd10b5c3164f8365e592d326f | |
parent | ae2898107d275176126ab07ca1886fd7fd7ddad4 (diff) | |
download | chat-4cfde35256cecab12d317e0d829769143f4df2d0.tar.gz chat-4cfde35256cecab12d317e0d829769143f4df2d0.tar.bz2 chat-4cfde35256cecab12d317e0d829769143f4df2d0.zip |
append * to search query if not present and highlight partial matches
-rw-r--r-- | web/react/components/search_bar.jsx | 4 | ||||
-rw-r--r-- | web/react/utils/text_formatting.jsx | 5 |
2 files changed, 7 insertions, 2 deletions
diff --git a/web/react/components/search_bar.jsx b/web/react/components/search_bar.jsx index e1d36ad7d..fae26f803 100644 --- a/web/react/components/search_bar.jsx +++ b/web/react/components/search_bar.jsx @@ -105,6 +105,10 @@ export default class SearchBar extends React.Component { performSearch(terms, isMentionSearch) { if (terms.length) { this.setState({isSearching: true}); + + if(terms.search(/\*\s*$/) == -1) // append * if not present + terms = terms + "*"; + client.search( terms, (data) => { diff --git a/web/react/utils/text_formatting.jsx b/web/react/utils/text_formatting.jsx index 5c2e68f1e..75f6cb714 100644 --- a/web/react/utils/text_formatting.jsx +++ b/web/react/utils/text_formatting.jsx @@ -243,10 +243,11 @@ function autolinkHashtags(text, tokens) { function highlightSearchTerm(text, tokens, searchTerm) { let output = text; + searchTerm = searchTerm.replace(/\*$/, ''); var newTokens = new Map(); for (const [alias, token] of tokens) { - if (token.originalText === searchTerm) { + if (token.originalText.indexOf(searchTerm) > -1) { const index = tokens.size + newTokens.size; const newAlias = `MM_SEARCHTERM${index}`; @@ -276,7 +277,7 @@ function highlightSearchTerm(text, tokens, searchTerm) { return prefix + alias; } - return output.replace(new RegExp(`(^|\\W)(${searchTerm})\\b`, 'gi'), replaceSearchTermWithToken); + return output.replace(new RegExp(`()(${searchTerm})`, 'gi'), replaceSearchTermWithToken); } function replaceTokens(text, tokens) { |