我刚开始一个项目,但是我无法让pg_search返回任何结果(这发生在几种不同的模型上)。创建该项目的开发人员可以在其环境中进行所有工作。我已经尝试过rake pg_search:multisearch:rebuild[User]
,但所有规格仍然失败。以下是我当前的设置:
宝石文件:
gem 'pg_search', '~> 2.0.1'
gem 'pg', '0.20.0'
user.rb:
class User < ApplicationRecord
include PgSearch
multisearchable against: [ :first_name, :last_name, :preferred_name, :email ]
# == Search Scopes ==========================
pg_search_scope :search,
against: {
preferred_name: 'A',
first_name: 'A',
last_name: 'B',
email: 'C'
},
ignoring: :accents,
using: {
tsearch: {
tsvector_column: 'tsv_body',
dictionary: 'english',
prefix: true
}
}
users_spec.rb:
describe "when params[:query] present" do
it "returns users that match the given search_query" do
get :index, params: { query: "mike" }
expect(data_user_ids(response)).to contain_exactly(user_1.id)
end
end
失败的规范消息:
1) Api::V1::UsersController GET #index filter/sort options behaves like a_users_controller_index_action when params[:query] present returns users that match the given search_query
Failure/Error: expect(data_user_ids(response)).to contain_exactly(user_1.id)
expected collection contained: [3593]
actual collection contained: []
the missing elements were: [3593]