MongoDB 关于 mongoid 中的 meta_search

rainchen · April 14, 2012 · Last by simlegate replied at March 13, 2013 · 3223 hits

目前需要使用 mongoid 的项目中加入一些复杂搜索,看了下貌似没有现成的 gem, 试了下 用 meta_search,在 model 中加入了 include MetaSearch::Searches::ActiveRecord (不知道插入的姿势对不对) 后用 MyModel.search(params[:search]) 会报一个 undefined method `joins_values' 错误。

另外不是需要 full text,所以不考虑 mongoid_fulltext mongoid-sphinx sunspot_mongoid mongoid_search 这些

搜索到一个 scoped-search,不过是 2010 的,目前在研究中

有经验的同学分享下相关经验或推荐一些好 gem

scoped_search 老是老了点,不过还是可以勉强一战,分享下我现在的做法抛砖引玉:

get :search do @search = Notification.scoped_search(params[:search] search_scope = @search.scoped defaul_scope = current_user.notifications result_scope = search_scope.merge defaul_scope @notifications = result_scope

render 'notifications/search' end

#1 楼 @rainchen 这东西貌似只支持 ActiveRecord 吧

You need to Sign in before reply, if you don't have an account, please Sign up first.