如何将Sequel.full_text_search
方法与PostgreSQLunaccent
中可用的函数结合使用,以返回与搜索词匹配的记录,而不考虑带有重音符号的字符?
例如:
# Given a user with first_name: Nícolas
User.full_text_search(:first_name, "nicolas").count
# Expected result to be 1, but it is 0
最佳答案
我们可以通过使用类来实现预期的结果:
# Given a user with first_name: Nícolas
col = Sequel.qualify(:users, :first_name)
col_without_accent = Sequel::SQL::Function.new(:UNACCENT, col)
Person.full_text_search(col_without_accent, "nicolas").count
# => 1
我们还可以对用于匹配结果的术语应用相同的
Sequel::SQL::Function
函数:Person.full_text_search(col_without_accent, Sequel::SQL::Function.new(:UNACCENT, "nícolas")).count
关于ruby - 如何使用Sequel gem将full_text_search与unaccent结合?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49006603/