标签: related-content

Google的相关搜索查询是否有可用的API?

当我Clooney在google.com上搜索时,会在底部建议一些相关的搜索查询:

Searches related to clooney
clooney movies
clooney girlfriend
rosemary clooney
nick clooney
clooney oscar
obama clooney
clooney fundraiser
betty clooney
Run Code Online (Sandbox Code Playgroud)

我希望以编程方式为单个或关键字列表接收此列表.有这样的API吗?

google-search related-content

7
推荐指数
3
解决办法
8374
查看次数

通过相关的多对多关联计数获取记录顺序

Scnerio:

https://www.funtraker.com正在列出电影,电视节目和游戏.在每个资源(电影,电视节目等)的显示页面上,我们要列出相关资源.

架构:

class Movie < AR::Base
  has_many :resource_genres, as: :resource
  has_many :genres, through: :resource_genres
end

class ResourceGenre
  belongs_to :resource, polymorphic: true
end
Run Code Online (Sandbox Code Playgroud)

现在我想得到一个基于匹配类型的相关电影列表(两部电影都是相关的,如果它们都有'喜剧'类型).这些相关电影需要按最大匹配类型排序.

那么这里是样本电影和预期的输出.

#Input
Movie         Genres
Movie 1:      horror, comedy, action, war
Movie 2:      action, thriller, crime, animation  
Movie 3:      comedy, war, action, thriller
Movie 4:      crime, animation, action, war

#Expected output
movie1.related_movies => [ movie3, movie2  ]
movie4.related_movies => [ movie2, remaining-three-movies-in-any-order ]
movie3.related_movies => [ movie1, movie2, movie4] 
Run Code Online (Sandbox Code Playgroud)

希望问题有意义.

更新:寻找仅SQL解决方案.我不需要将结果缓存在任何其他表中.

postgresql activerecord join ruby-on-rails related-content

5
推荐指数
1
解决办法
508
查看次数