0
0
Fork 0

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:
Matt Jankowski 2017-04-09 08:45:01 -04:00 committed by Eugen
parent 71706f21c2
commit 388ec0d5b6
4 changed files with 74 additions and 8 deletions

View file

@ -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