gpt4 book ai didi

ruby-on-rails-3 - Postgres 全文与 Rails 3 中的部分单词不匹配?

转载 作者:行者123 更新时间:2023-11-29 11:42:10 25 4
gpt4 key购买 nike

我刚从 MySQL 迁移到 Postgres 9.0.3。我有一个带有少量数据(游戏数据)的全新应用。

反正我好像搜不到部分词。这是我的搜索方法:

def self.search(query)
conditions = <<-EOS
to_tsvector('english', title) @@ plainto_tsquery('english', ?)
EOS

find(:all, :conditions => [conditions, query])
end

我确定我需要一个通配符,但我只是在学习 Postgres。

当我搜索 Shinobi 时,我得到了正确的结果:

Alex Kidd in Shinobi World - Sega Master System

Shinobi - Sega Master System

Shinobi - Nintendo Entertainment System

The Cyber Shinobi: Shinobi Part 2 - Sega Master System

但是当我搜索 Shin 时,我什么也没找到?

感谢您提供任何线索。

最佳答案

我认为要允许前缀匹配,您需要使用 to_tsquery 而不是 plainto_tsquery

上面写着 http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES

所以你的代码可以是这样的

def self.search(query)
conditions = <<-EOS
to_tsvector('english', title) @@ to_tsquery('english', ?)
EOS

find(:all, :conditions => [conditions, query + ':*'])
end

关于ruby-on-rails-3 - Postgres 全文与 Rails 3 中的部分单词不匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5086325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com