我跟隨Ryan Bates的Railscast與Postgres進行全文搜索,但是,他使用的是postgres 9.1,而我使用的是9.2。他構建了以下查詢來執行搜索。它對我有用,如果我的查詢是一個單詞,如「超人」,但如果它是兩個單詞,如dc comics
或super man
,我得到這個錯誤,這只是新的postgres我無法弄清楚如何修理。你能幫忙嗎?從Article.rb如果使用空間postgres搜索查詢錯誤
def self.text_search(query)
if query.present?
rank = <<-RANK
ts_rank(to_tsvector(name), plainto_tsquery(#{sanitize(query)})) +
ts_rank(to_tsvector(content), plainto_tsquery(#{sanitize(query)}))
RANK
where("to_tsvector('english', name) @@ :q or to_tsvector('english', content) @@ :q", q: query).order("#{rank} desc")
else
scoped
end
end
感謝您的幫助。然而,我把這個':q'包裝了兩遍,但是,儘管它現在在兩個單詞搜索(如'has been')中沒有被破壞,但是它不會返回任何結果,即使''has''存在於我的分貝的內容。這是你期望的嗎?無論如何,使它檢索多詞搜索查詢結果? (where)(「to_tsvector('english',name)@@ plainto_tsquery(:q)或to_tsvector('english',content)@@ plainto_tsquery(:q)」,q:query).order(「#{rank} desc 「)' – BrainLikeADullPencil 2013-05-09 16:13:11
請閱讀[停用詞](http://www.postgresql.org/docs/9.2/static/textsearch-dictionaries.html)。在英語詞典中,「擁有」和「被」一詞在英語詞典中被認爲太常見了,以此來打擾索引它們。 – 2013-05-09 16:14:36
好的,我明白了。它正在返回不太常見的單詞的結果。謝謝。 – BrainLikeADullPencil 2013-05-09 16:16:57