我已将以下内容添加到我的 gemfile 中:
gem 'texticle', "2.0", :require => 'texticle/rails' # search gem
然后我运行bundle install
并捆绑安装了 gem
我正在使用 Rails 3.1.0,并且正在使用 Postgres 数据库。
我确认我确实在数据库表中找到了我要查找的字符串:
ruby-1.9.2-p290 :004 > Hotel.first
Hotel Load (0.4ms) SELECT "hotels".* FROM "hotels" LIMIT 1
=> #<Hotel id: 1, title: "Marriot Hotel", created_at: "2012-03-01 23:53:16", updated_at: "2012-03-01 23:53:16">
当我运行 `Hotel.search('e')
ruby-1.9.2-p290 :005 > Hotel.search(:title => 'e')
Hotel Load (1.4ms) SELECT "hotels".*, ts_rank(to_tsvector("hotels"."title"), to_tsquery('e')) AS "rank0.4785527956789428" FROM "hotels" WHERE (to_tsvector('english', "title") @@ to_tsquery('e')) ORDER BY "rank0.4785527956789428" DESC
=> []
我什么都得不到。我试着跑步Hotel.search('e')
,还是什么都没有。如果我尝试Hotel.search(:title => 'Marriot')
,那么它可以工作,但我使用 Texticle 的原因是为了模糊搜索。
我是否缺少任何其他配置?
谢谢