Fix full-text search query quotation, improve tag search performance with an index,
add ability to open status by URL from search (fix #53)
This commit is contained in:
@ -13,8 +13,9 @@ class Tag < ApplicationRecord
|
||||
|
||||
class << self
|
||||
def search_for(terms, limit = 5)
|
||||
terms = Arel.sql(connection.quote(terms.gsub(/['?\\:]/, ' ')))
|
||||
textsearch = 'to_tsvector(\'simple\', tags.name)'
|
||||
query = 'to_tsquery(\'simple\', \'\'\' \' || ? || \' \'\'\' || \':*\')'
|
||||
query = 'to_tsquery(\'simple\', \'\'\' \' || ' + terms + ' || \' \'\'\' || \':*\')'
|
||||
|
||||
sql = <<SQL
|
||||
SELECT
|
||||
@ -26,7 +27,7 @@ class Tag < ApplicationRecord
|
||||
LIMIT ?
|
||||
SQL
|
||||
|
||||
Tag.find_by_sql([sql, terms, terms, limit])
|
||||
Tag.find_by_sql([sql, limit])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user