How should I index the terms table for maximum speed? It doesn't have to be
Rails migration doable. E.g. a primary key of (user_id, article_id, fnv) is
okay. fnv is a 63 bit Fowler-Noll-Vo hash.
def self.neighbors(user_id, article_id)
sql = "SELECT t1.article_id, SUM(t1.freq * t2.freq) AS cosim FROM " \
"tokens AS t1 JOIN tokens AS t2 " \
"ON t1.fnv = t2.fnv WHERE t1.user_id = #{user_id} AND t2.user_id =
#{user_id} AND " \
"t1.scoring = 1 AND t2.scoring = 0 AND t2.article_id = #{article_id} GROUP
BY t1.article_id " \
"ORDER BY cosim DESC LIMIT 3"
connection.select_rows(sql)
end
TIA,
Jeffrey
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.