Sha256: fc35865860f43e9d6af955bd0edf49c891367498da84b58bb5cf0eac89650b3f

Contents?: true

Size: 1.34 KB

Versions: 18

Compression:

Stored size: 1.34 KB

Contents

require 'algoliasearch'

namespace :search_terms do
  desc 'Publish search terms to Algolia'
  task 'algolia:generate', %i[locale] => :environment do |_, args|
    unless ENV['ALGOLIA_APPLICATION_ID']
      puts 'Not rebuilding search index, Algolia Application ID not set'
      next
    end

    Algolia.init(application_id: ENV['ALGOLIA_APPLICATION_ID'], api_key: ENV['ALGOLIA_API_KEY'])
    index = Algolia::Index.new "#{Rails.env}_nexmo_developer"
    search_articles = SearchTerms.generate(args.fetch(:locale, I18n.default_locale))

    search_articles.each do |search_article|
      index.add_object(search_article)
    rescue Algolia::AlgoliaProtocolError
      # puts search_article
      puts "#{search_article[:document_path]} could not be processed"
    end
  end

  desc 'Clear the index in Algolia'
  task 'algolia:clear': :environment do
    unless ENV['ALGOLIA_APPLICATION_ID']
      puts 'Not rebuilding search index, Algolia Application ID not set'
      next
    end
    Algolia.init(application_id: ENV['ALGOLIA_APPLICATION_ID'], api_key: ENV['ALGOLIA_API_KEY'])
    index = Algolia::Index.new "#{Rails.env}_nexmo_developer"
    index.clear_index
  end

  desc 'Refresh the Algolia index'
  task 'algolia:refresh': :environment do
    Rake::Task['search_terms:algolia:clear'].invoke
    Rake::Task['search_terms:algolia:generate'].invoke
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
station-0.0.113 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.112 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.111 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.110 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.109 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.108 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.107 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.106 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.105 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.104 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.103 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.102 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.101 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.100 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.97 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.96 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.95 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.0.93 lib/nexmo_developer/lib/tasks/generate_search_terms.rake