add prefix index on tags (#3858)

This commit is contained in:
Albert Yi
2018-09-12 14:01:21 -07:00
parent f487b2a2c6
commit 8c564f055f
3 changed files with 16 additions and 3 deletions

View File

@@ -78,9 +78,9 @@ module TagAutocomplete
n += 2
end
anchors = "^" + query.split("").map {|x| Regexp.escape(x)}.join(".*[#{PREFIX_BOUNDARIES}]")
regexp = "([a-z0-9])[a-z0-9']*($|[^a-z0-9']+)"
Tag
.where("name ~ ?", anchors)
.where('regexp_replace(name, ?, ?, ?) like ?', regexp, '\1', 'g', query.to_escaped_for_sql_like + '%')
.where("post_count > ?", min_post_count)
.where("post_count > 0")
.order("post_count desc")