2011-02-27 46 views
0

我有一個Ruby on Rails模型,有很多HABTM關係。從本質上講,我製作了一個視頻分享網站,主要圍繞爲客戶提供滑板遊戲。每個視頻都有許多通過HABTM的attirbutes:位置,滑板,標籤,位置,音樂,設備,地點,地區等......它也有一些重要的類別屬性:標題,說明等...如何通過屬性處理相關對象?

這裏的想法是我的客戶想要每個視頻播放器提供的「相關視頻」,使用所有以前提到的描述性數據。此外,信息應加權(類似的標題優先於類似的標籤)。

我試圖找到一個很好的方式實現谷歌網站搜索功能來處理繁重的工作,但不能找到一個很好的搜索詞的語法即:

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

,它實際上並不工作,遺憾的是.. 。

回答

0

解決了這個問題,使用雪貂做關鍵字爆炸搜索。

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 
0

那麼,您正在尋找一個搜索字詞來使用以查找您的視頻?我對這個問題不太確定,但如果是這樣,這對你有用嗎?

site:example.com inurl:videos 
+0

我基本上試圖找到最好的方式來處理「相關視頻」基於許多屬性,我想也許使用谷歌的「相關」搜索功能的力量...... – 2011-02-28 14:17:55