我有一个Mongoid
模型,我在上面执行ElasticSearch
搜索查询。非常标准:
class ActivityLog
include Mongoid::Document
include Mongoid::Timestamps
include Tire::Model::Search
include Tire::Model::Callbacks
field :extra, type: Hash
belongs_to :user, :inverse_of => :activity_logs
def self.search(params, user)
tire.search(load: true, page: params[:page], per_page: 5) do
query { string params[:query], default_operator: "AND" } if params[:query].present?
sort { by :created_at, "desc" }
end
end
我很难理解有关如何做更高级事情的文档,目前我被困在如何处理我的搜索查询中,即搜索应该仅限于ActivityLog
属于用户的对象。
谁能告诉我如何在搜索查询中使用 user._id 匹配要求?