Remove non-Postgres search codepath

(imported from commit ebc71defce2f075ee224f17a40088ccda9fab931)
This commit is contained in:
Zev Benjamin
2013-12-02 14:29:57 -05:00
parent 6c96561624
commit 8142646938

View File

@@ -189,34 +189,28 @@ class NarrowBuilder(object):
(self.pQ(sender=self.user_profile) & self.pQ(recipient=narrow_recipient))) (self.pQ(sender=self.user_profile) & self.pQ(recipient=narrow_recipient)))
def do_search(self, query, operand): def do_search(self, query, operand):
if "postgres" in settings.DATABASES["default"]["ENGINE"]: tsquery = "plainto_tsquery('zulip.english_us_search', %s)"
tsquery = "plainto_tsquery('zulip.english_us_search', %s)" where = "search_tsvector @@ " + tsquery
where = "search_tsvector @@ " + tsquery content_matches = "ts_match_locs_array('zulip.english_us_search', rendered_content, " \
content_matches = "ts_match_locs_array('zulip.english_us_search', rendered_content, " \ + tsquery + ")"
+ tsquery + ")" # We HTML-escape the subject in Postgres to avoid doing a server round-trip
# We HTML-escape the subject in Postgres to avoid doing a server round-trip subject_matches = "ts_match_locs_array('zulip.english_us_search', escape_html(subject), " \
subject_matches = "ts_match_locs_array('zulip.english_us_search', escape_html(subject), " \ + tsquery + ")"
+ tsquery + ")"
# Do quoted string matching. We really want phrase # Do quoted string matching. We really want phrase
# search here so we can ignore punctuation and do # search here so we can ignore punctuation and do
# stemming, but there isn't a standard phrase search # stemming, but there isn't a standard phrase search
# mechanism in Postgres # mechanism in Postgres
for term in re.findall('"[^"]+"|\S+', operand): for term in re.findall('"[^"]+"|\S+', operand):
if term[0] == '"' and term[-1] == '"': if term[0] == '"' and term[-1] == '"':
term = term[1:-1] term = term[1:-1]
query = query.filter(self.pQ(content__icontains=term) | query = query.filter(self.pQ(content__icontains=term) |
self.pQ(subject__icontains=term)) self.pQ(subject__icontains=term))
return query.extra(select={'content_matches': content_matches, return query.extra(select={'content_matches': content_matches,
'subject_matches': subject_matches}, 'subject_matches': subject_matches},
where=[where], where=[where],
select_params=[operand, operand], params=[operand]) select_params=[operand, operand], params=[operand])
else:
for word in operand.split():
query = query.filter(self.pQ(content__icontains=word) |
self.pQ(subject__icontains=word))
return query
def highlight_string(string, locs): def highlight_string(string, locs):
highlight_start = '<span class="highlight">' highlight_start = '<span class="highlight">'