summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-10-26 08:56:30 -0400
committerChristopher Speller <crspeller@gmail.com>2015-10-26 08:56:30 -0400
commit3b3cc234eb87ad3358671944537300ac17a9db41 (patch)
tree86bf26a4a0ea1072be8c944d52cf0ebf798d350d /web
parentf05da1fa6d028bfb15b2838abbb7976c29bff1cd (diff)
parente9812655f6cb7e9e6c06bc1b2a462efc106f52f7 (diff)
downloadchat-3b3cc234eb87ad3358671944537300ac17a9db41.tar.gz
chat-3b3cc234eb87ad3358671944537300ac17a9db41.tar.bz2
chat-3b3cc234eb87ad3358671944537300ac17a9db41.zip
Merge pull request #1181 from girishso/star-search2
PLT-747: Allow search results to match portions of words
Diffstat (limited to 'web')
-rw-r--r--web/react/components/search_bar.jsx9
-rw-r--r--web/react/utils/text_formatting.jsx4
2 files changed, 10 insertions, 3 deletions
diff --git a/web/react/components/search_bar.jsx b/web/react/components/search_bar.jsx
index e1d36ad7d..0da43e8cd 100644
--- a/web/react/components/search_bar.jsx
+++ b/web/react/components/search_bar.jsx
@@ -105,8 +105,15 @@ export default class SearchBar extends React.Component {
performSearch(terms, isMentionSearch) {
if (terms.length) {
this.setState({isSearching: true});
+
+ // 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 5c2e68f1e..204c37364 100644
--- a/web/react/utils/text_formatting.jsx
+++ b/web/react/utils/text_formatting.jsx
@@ -246,7 +246,7 @@ function highlightSearchTerm(text, tokens, searchTerm) {
var newTokens = new Map();
for (const [alias, token] of tokens) {
- if (token.originalText === searchTerm) {
+ if (token.originalText.indexOf(searchTerm.replace(/\*$/, '')) > -1) {
const index = tokens.size + newTokens.size;
const newAlias = `MM_SEARCHTERM${index}`;
@@ -276,7 +276,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) {