mirror of
https://github.com/zulip/zulip.git
synced 2026-07-15 21:03:26 +08:00
Make searching for multiple words be treated as the boolean AND of those words
(imported from commit d9e47dd25553cc31eeda615e3a5709436e883ab3)
This commit is contained in:
parent
6d5424c910
commit
d5fdfd7be2
@ -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;
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user