-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to override search #343
Comments
+1 This would also be helpful in large databases for searching by id. |
+1 - I'm already running out of memory for some large datasets on Heroku that are put into drop-down boxes by default. |
+1 — using rails_admin as a contacts database, and it's brilliant, right out of the box. Only searching across associations is slow. |
need custom search to filter result from mongodb data type Array |
Big +1 on this. I love that there is a search function out of the box for every model, but I already have ElasticSearch indexing a few of my models so for them I would prefer to search using the |
Big +1 on this too. |
Big +1 too! |
Hi there, My solution: # /config/initializers/rails_admin.rb
RailsAdmin::MainController.class_eval do
# Override the list_entries method of the RailsAdmin::MainController
def list_entries(model_config = @model_config, auth_scope_key = :index, additional_scope = get_association_scope_from_params, pagination = !(params[:associated_collection] || params[:all] || params[:bulk_ids]))
scope = model_config.abstract_model.scoped
if auth_scope = @authorization_adapter && @authorization_adapter.query(auth_scope_key, model_config.abstract_model)
scope = scope.merge(auth_scope)
end
scope = scope.instance_eval(&additional_scope) if additional_scope
if params[:query].present? and model_config.abstract_model.is_a?(YOUR_MODEL).inspect
solr_search(model_config, scope, pagination)
else
get_collection(model_config, scope, pagination)
end
end
#Custom query if params[:query] is set and the model ist YOUR MODEL
def solr_search(model_config, scope, pagination)
search_term = ""
params[:query].gsub(/[_\?\*\~\"]/, '').split(' ').each do |word|
search_term += word + " "
end
search_term
search = YOUR_MODEL.search do
fulltext search_term, :fields => [:your_field]
paginate :page => 1, :per_page => (params[:per] || model_config.list.items_per_page)
end
results = []
search.each_hit_with_result do |hit, YOUR_MODEL|
results.push YOUR_MODEL
end
return results
end Hope it helps someone to boost the search action of rails_admin. |
It would be great if we could override the default search mechanic, to allow for a customized search on a per model bases. For example, one way to do this would be to have a config setting such as
or globally for all models
This would mean in the case of the Car model, searches would be performed by calling:
dynamically in preference to the default search. This would of course return a list of Car models which would be understood by rails admin and rendered in the search results.
This would be a very powerful feature as it would allow users to customize searches and potentially use search indexers such as Sphinx/Solr etc.. to perform the actual search in the background.
I would like to hear other any other comments/suggestions ?
The text was updated successfully, but these errors were encountered: