diff --git a/zephyr/static/js/narrow.js b/zephyr/static/js/narrow.js index 44ba66f314..4961973a65 100644 --- a/zephyr/static/js/narrow.js +++ b/zephyr/static/js/narrow.js @@ -152,10 +152,14 @@ function build_filter(operators_mixed_case) { break; case 'search': - if (message.content.toLowerCase().indexOf(operand) === -1) { - if ((message.type !== 'stream') || - (message.subject.toLowerCase().indexOf(operand) === -1)) { - return false; + var words = operand.trim().split(/\s+/); + var j; + for (j = 0; j < words.length; ++j) { + if (message.content.toLowerCase().indexOf(words[j]) === -1) { + if ((message.type !== 'stream') || + (message.subject.toLowerCase().indexOf(words[j]) === -1)) { + return false; + } } } break; diff --git a/zephyr/views.py b/zephyr/views.py index 32b5e841da..f0559bd57f 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -559,12 +559,15 @@ class NarrowBuilder(object): (Q(sender=self.user_profile) & Q(recipient=narrow_recipient))) def do_search(self, query, operand): + words = operand.split() if "postgres" in settings.DATABASES["default"]["ENGINE"]: sql = "to_tsvector('english', subject || ' ' || content) @@ to_tsquery('english', %s)" - return query.extra(where=[sql], params=[operand]) + return query.extra(where=[sql], params=[" & ".join(words)]) else: - return query.filter(Q(content__icontains=operand) | - Q(subject__icontains=operand)) + for word in words: + query = query.filter(Q(content__icontains=word) | + Q(subject__icontains=word)) + return query def narrow_parameter(json):