Search cleanup (#1333)
* Clean up SQL output in Tag and Account search methods * Add basic coverage for Tag.search_for * Add coverage for Account.search_for * Add coverage for Account.advanced_search_for
This commit is contained in:
parent
71706f21c2
commit
388ec0d5b6
4 changed files with 74 additions and 8 deletions
|
@ -17,7 +17,7 @@ class Tag < ApplicationRecord
|
|||
textsearch = 'to_tsvector(\'simple\', tags.name)'
|
||||
query = 'to_tsquery(\'simple\', \'\'\' \' || ' + terms + ' || \' \'\'\' || \':*\')'
|
||||
|
||||
sql = <<SQL
|
||||
sql = <<-SQL.squish
|
||||
SELECT
|
||||
tags.*,
|
||||
ts_rank_cd(#{textsearch}, #{query}) AS rank
|
||||
|
@ -25,7 +25,7 @@ class Tag < ApplicationRecord
|
|||
WHERE #{query} @@ #{textsearch}
|
||||
ORDER BY rank DESC
|
||||
LIMIT ?
|
||||
SQL
|
||||
SQL
|
||||
|
||||
Tag.find_by_sql([sql, limit])
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue