1
我正在使用rails的acts_as_tsearch插件來使用Postgresql進行全文搜索。SQL搜索與acts_as_tsearch多對多的關係
他們給這裏多表搜索的例子: http://code.google.com/p/acts-as-tsearch/wiki/ActsAsTsearchMethod
但這隻做一個一對多的關係。我試圖讓它也爲頁面上的標籤搜索多對多關係(has_and_belongs_to_many或habtm)。但是我的SQL不夠先進。
這裏是我到目前爲止有:
acts_as_tsearch :vectors => {
:fields => {
"a" => {:columns => ["pages.name"], :weight => 1.0},
"b" => {:columns => ["pages.description"], :weight => 0.2},
"c" => {:columns => ["tags.name"], :weight => 0.2}
},
:tables => {
:tags => {
:from => "tags INNER JOIN taggings ON tags.id = taggings.tag_id",
:where => "((taggings.taggable_type = 'Page') AND (taggings.taggable_id = ???.id) AND ((taggings.context = 'tags')))"
}
}
}
我不知道如何引用頁面ID(這裏我把???)。
感謝您的幫助!
你能解釋一下taggable_id的用途嗎? – Andomar 2009-04-23 07:37:52