如何通过属性来处理相关对象?

发布于 2024-10-19 14:52:13 字数 395 浏览 1 评论 0原文

我有一个 Ruby on Rails 模型,其中有很多 HABTM 关系。本质上,我正在为客户制作一个以滑板为主题的视频共享网站。每个视频通过 HABTM 都有许多属性:位置、滑板者、标签、位置、音乐、设备、地点、区域等...并且它还有一些重要的类属性:标题、描述等

...我的客户希望每个视频播放器使用所有前面提到的描述性数据提供“相关视频”提要。此外,信息应该被加权(相似的标题优先于相似的标签)。

我试图找到一种实现 Google SiteSearch 来处理繁重工作的好方法,但找不到好的搜索词语法,即:

inurl: example.com/videos related:example.com/videos/4638872 

不幸的是,这实际上不起作用......

I have a Ruby on Rails model that has quite a few HABTM relationships. Essentially, i'm making a video sharing site themed around skateboarding for a client. Each video has many attirbutes through HABTM: Location, Skateboarders, tags, location, music, equipment, spot, region, etc... And it also has a few class attributes that are significant: Title, description, etc...

The idea here is my client would like a "Related Videos" feed by each video player, using all of the formerly mentioned descriptive data. Furthermore, the information should be weighted (similar titles take precedence over similar tags).

I was trying to find a good way implement Google SiteSearch to handle the grunt work, but can't find a good search term syntax ie:

inurl: example.com/videos related:example.com/videos/4638872 

Which doesn't actually work, unfortunately...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

靖瑶 2024-10-26 14:52:13

那么,您正在寻找一个搜索词来查找您的视频吗?我不太确定这个问题,但如果是这样,这对你有用吗?

site:example.com inurl:videos

So, you are looking for a search term to use in order to locate your videos ? I'm not so sure about the question, but if so, would this work for you ?

site:example.com inurl:videos
漫雪独思 2024-10-26 14:52:13

通过使用 ferret 进行关键字爆炸搜索解决了这个问题。

def related
    string = self.name + " " + self.tag_name + " " + self.skateboarder_name + " " + self.category_name + " " + self.editor_name
    #probably could have used "join" there...
    s = "*" + string.gsub(" ", "* OR *") + "*"
    relates = Video.find_with_ferret(s)
    #takes out duplicates and gices 10 to choose from
    while relates.count <= 10
        relates << Video.random
        relates = relates.uniq
    end
    #take out original video
    relates = relates - [Video.find(self.id)]
    #send back with "middle data"... for some reason i thought this might be more accurate....
    return relates[1..8]
end

Solved this by using ferret to do a keyword explode search.

def related
    string = self.name + " " + self.tag_name + " " + self.skateboarder_name + " " + self.category_name + " " + self.editor_name
    #probably could have used "join" there...
    s = "*" + string.gsub(" ", "* OR *") + "*"
    relates = Video.find_with_ferret(s)
    #takes out duplicates and gices 10 to choose from
    while relates.count <= 10
        relates << Video.random
        relates = relates.uniq
    end
    #take out original video
    relates = relates - [Video.find(self.id)]
    #send back with "middle data"... for some reason i thought this might be more accurate....
    return relates[1..8]
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文