From 4cfde35256cecab12d317e0d829769143f4df2d0 Mon Sep 17 00:00:00 2001 From: Girish S Date: Mon, 26 Oct 2015 12:25:14 +0530 Subject: append * to search query if not present and highlight partial matches --- web/react/components/search_bar.jsx | 4 ++++ web/react/utils/text_formatting.jsx | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'web/react') 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) { -- cgit v1.2.3-1-g7c22 From e9812655f6cb7e9e6c06bc1b2a462efc106f52f7 Mon Sep 17 00:00:00 2001 From: Girish S Date: Mon, 26 Oct 2015 13:00:26 +0530 Subject: made eslint happy --- web/react/components/search_bar.jsx | 9 ++++++--- web/react/utils/text_formatting.jsx | 5 ++--- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'web/react') diff --git a/web/react/components/search_bar.jsx b/web/react/components/search_bar.jsx index fae26f803..0da43e8cd 100644 --- a/web/react/components/search_bar.jsx +++ b/web/react/components/search_bar.jsx @@ -106,11 +106,14 @@ export default class SearchBar extends React.Component { if (terms.length) { this.setState({isSearching: true}); - if(terms.search(/\*\s*$/) == -1) // append * if not present - terms = terms + "*"; + // append * if not present + let searchTerms = terms; + if (searchTerms.search(/\*\s*$/) === -1) { + searchTerms = searchTerms + '*'; + } client.search( - terms, + searchTerms, (data) => { this.setState({isSearching: false}); if (utils.isMobile()) { diff --git a/web/react/utils/text_formatting.jsx b/web/react/utils/text_formatting.jsx index 75f6cb714..204c37364 100644 --- a/web/react/utils/text_formatting.jsx +++ b/web/react/utils/text_formatting.jsx @@ -243,11 +243,10 @@ 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.indexOf(searchTerm) > -1) { + if (token.originalText.indexOf(searchTerm.replace(/\*$/, '')) > -1) { const index = tokens.size + newTokens.size; const newAlias = `MM_SEARCHTERM${index}`; @@ -277,7 +276,7 @@ function highlightSearchTerm(text, tokens, searchTerm) { return prefix + alias; } - return output.replace(new RegExp(`()(${searchTerm})`, 'gi'), replaceSearchTermWithToken); + return output.replace(new RegExp(`()(${searchTerm})`, 'gi'), replaceSearchTermWithToken); } function replaceTokens(text, tokens) { -- cgit v1.2.3-1-g7c22