Skip to content
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

Rake task mongoid_search:index doesn't work #121

Open
rtrv opened this issue Oct 30, 2017 · 2 comments
Open

Rake task mongoid_search:index doesn't work #121

rtrv opened this issue Oct 30, 2017 · 2 comments

Comments

@rtrv
Copy link
Collaborator

rtrv commented Oct 30, 2017

I've tried this tasks and it faild, because Mongoid::Search.classes returned [Object]. Maybe the problem is in nesting: Mongoid::Search is included into another concern, which is included to models. Any thoughts/suggestions?

@rgaufman
Copy link

Any workaround for this?

@NikolaiIvanov
Copy link

Mongoid::Search.classes returns Array < Object
Also you can make own rake task to loop Models.

namespace :mongoid_search do
  desc 'Goes through all documents with search enabled and indexes the keywords.'
  task :index => :environment do
    ::Rails.application.eager_load!
    if Mongoid::Search.classes.blank?
      Mongoid::Search::Log.log "No model to index keywords.\n"
    else
      Mongoid::Search.classes.each do |klass|
        Mongoid::Search::Log.silent = ENV['SILENT']
        Mongoid::Search::Log.log "\nIndexing documents for #{klass.name}:\n"
        klass.index_keywords!
      end
      Mongoid::Search::Log.log "\n\nDone.\n"
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants