Sha256: 51161afffcdf1125eeba5a968c11d56c09344f718f9685f1235a534053e323f6

Contents?: true

Size: 1.34 KB

Versions: 76

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

76 entries across 76 versions & 1 rubygems

Version Path
station-0.5.16 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.15 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.14 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.13 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.12 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.11 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.10 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.9 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.8 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.7 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.6 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.5 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.4 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.3 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.2 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.1 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.5.0 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.4.9 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.4.8 lib/nexmo_developer/lib/tasks/generate_search_terms.rake
station-0.4.7 lib/nexmo_developer/lib/tasks/generate_search_terms.rake