move_alias_to

in lib/tasks/search.rake [21:45]


  def move_alias_to(name, index)
    
    alias_ = Tire::Alias.find name
    if alias_
      
      if alias_.indices.include? index.name
        return false
      end
      
      LOG.info "alias already exists (will move): #{alias_.indices.to_ary.join(',')}"
      alias_.indices.each do |old_index_name|
        alias_.indices.delete old_index_name unless old_index_name == name
      end
    else
      
      LOG.info "alias \"#{name}\" does not yet exist - creating."
      alias_ = Tire::Alias.new :name => name
    end
    
    alias_.indices.add index.name
    alias_.save
    LOG.info "alias \"#{name}\" now points to index #{index.name}."
    true
  end