I've added a fulltext searching database to my existing webapp that is built with Rails and uses the active_admin gem. The fulltext database is built on elastic search and uses the Tire gem. The active_admin gem has a dependency requirement of the metasearch gem which defines the Model.search method.
The problem is that the metasearch gem overrides the search method for the tire search gem and I can't seem to alias the search method in the tire gem back into the model. Does anyone know how I can do this?
-- Solution --
Update: The solution is to setup an initializer to add the following method:
def search_for(*args,&block)
tire.__send__(:search, *args, &block)
end
I've come up with a working solution. Basically, you need to just set the search method to be called search_for
instead of search
.
Create a helper file called tire_helper.rb within app/helpers.
module TireHelper
def search_for(*args,&block)
tire.__send__(:search, *args, &block)
end
end
And for each model that uses tire then use this:
class Model < ActiveRecord::Base
extend TireHelper
include Tire::Model::Search
include Tire::Model::Callbacks
mapping do
# your mappings
end
end
You can now search normally on your model(s) with the following method:
# with a string
query = Model.search_for('string')
# or with a block
query = Model.search_for do
#any of the same block stuff that Tire.search provides
end
或者,您可以在没有任何帮助的情况下使用MyModel.tire.search("string")
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.