@ -203,7 +203,7 @@ class Account < ApplicationRecord
end
end
def triadic_closures ( account , limit = 5 )
def triadic_closures ( account , limit = 5 )
sql = << SQL
sql = << - SQL . squish
WITH first_degree AS (
WITH first_degree AS (
SELECT target_account_id
SELECT target_account_id
FROM follows
FROM follows
@ -216,7 +216,7 @@ class Account < ApplicationRecord
GROUP BY target_account_id , accounts . id
GROUP BY target_account_id , accounts . id
ORDER BY count ( account_id ) DESC
ORDER BY count ( account_id ) DESC
LIMIT ?
LIMIT ?
SQL
SQL
Account . find_by_sql ( [ sql , account . id , account . id , limit ] )
Account . find_by_sql ( [ sql , account . id , account . id , limit ] )
end
end
@ -226,7 +226,7 @@ SQL
textsearch = '(setweight(to_tsvector(\'simple\', accounts.display_name), \'A\') || setweight(to_tsvector(\'simple\', accounts.username), \'B\') || setweight(to_tsvector(\'simple\', coalesce(accounts.domain, \'\')), \'C\'))'
textsearch = '(setweight(to_tsvector(\'simple\', accounts.display_name), \'A\') || setweight(to_tsvector(\'simple\', accounts.username), \'B\') || setweight(to_tsvector(\'simple\', coalesce(accounts.domain, \'\')), \'C\'))'
query = 'to_tsquery(\'simple\', \'\'\' \' || ' + terms + ' || \' \'\'\' || \':*\')'
query = 'to_tsquery(\'simple\', \'\'\' \' || ' + terms + ' || \' \'\'\' || \':*\')'
sql = << SQL
sql = << - SQL . squish
SELECT
SELECT
accounts . * ,
accounts . * ,
ts_rank_cd ( #{textsearch}, #{query}, 32) AS rank
ts_rank_cd ( #{textsearch}, #{query}, 32) AS rank
@ -234,7 +234,7 @@ SQL
WHERE #{query} @@ #{textsearch}
WHERE #{query} @@ #{textsearch}
ORDER BY rank DESC
ORDER BY rank DESC
LIMIT ?
LIMIT ?
SQL
SQL
Account . find_by_sql ( [ sql , limit ] )
Account . find_by_sql ( [ sql , limit ] )
end
end
@ -244,7 +244,7 @@ SQL
textsearch = '(setweight(to_tsvector(\'simple\', accounts.display_name), \'A\') || setweight(to_tsvector(\'simple\', accounts.username), \'B\') || setweight(to_tsvector(\'simple\', coalesce(accounts.domain, \'\')), \'C\'))'
textsearch = '(setweight(to_tsvector(\'simple\', accounts.display_name), \'A\') || setweight(to_tsvector(\'simple\', accounts.username), \'B\') || setweight(to_tsvector(\'simple\', coalesce(accounts.domain, \'\')), \'C\'))'
query = 'to_tsquery(\'simple\', \'\'\' \' || ' + terms + ' || \' \'\'\' || \':*\')'
query = 'to_tsquery(\'simple\', \'\'\' \' || ' + terms + ' || \' \'\'\' || \':*\')'
sql = << SQL
sql = << - SQL . squish
SELECT
SELECT
accounts . * ,
accounts . * ,
( count ( f . id ) + 1 ) * ts_rank_cd ( #{textsearch}, #{query}, 32) AS rank
( count ( f . id ) + 1 ) * ts_rank_cd ( #{textsearch}, #{query}, 32) AS rank
@ -254,7 +254,7 @@ SQL
GROUP BY accounts . id
GROUP BY accounts . id
ORDER BY rank DESC
ORDER BY rank DESC
LIMIT ?
LIMIT ?
SQL
SQL
Account . find_by_sql ( [ sql , account . id , account . id , limit ] )
Account . find_by_sql ( [ sql , account . id , account . id , limit ] )
end
end