namespace :rummager do
  desc "index all published documents in rummager"
  task index: :environment do
    require 'plek'
    require 'rummageable'

    root_document = {
      format: "manual",
      title: "Government Service Design Manual",
      description: "All new digital services from the government must meet the Digital by Default Service Standard",
      link: "/service-manual",
      organisations: "government-digital-service",
    }
    index_document root_document

    Guide.all.each do |guide|
      edition = guide.latest_edition
      if edition.published?
        puts "Indexing #{edition.title}..."
        index_document({
          "format": "service_manual_guide",
          "_type": "service_manual_guide",
          "description": edition.description,
          "indexable_content": edition.body,
          "title": edition.title,
          "link": guide.slug,
          "manual": "/service-manual",
          "organisations": [ "government-digital-service" ],
        })
      end
    end
  end

  def index_document document
    @rummageable_index ||= Rummageable::Index.new(
      Plek.current.find('rummager'), '/mainstream'
    )
    @rummageable_index.add_batch([document])
  end
end

namespace :rummager do
  desc "index all published documents in rummager"
  task index: :environment do
    Guide.all.each do |guide|
      puts "Indexing #{guide.title}..."

      SearchIndexer.new(guide).index
    end
  end
end

Stop indexing root and use SearchIndexer in the rake task
Stop indexing root and use SearchIndexer in the rake task

We haven't migrated the root yet so we don't want it to appear in both indexes and therefore twice.
