  We present time-resolved optical spectroscopy of the `redback' binary
millisecond pulsar system PSR J1023+0038 during both its radio pulsar (2009)
and accretion disc states (2014 and 2016). We provide observational evidence
for the companion star being heated during the disc-state. We observe a
spectral type change along the orbit, from G5 to F6 at the secondary star's
superior and inferior conjunction, respectively, and find that the
corresponding irradiating luminosity can be powered by the high energy
accretion luminosity or the spin-down luminosity of the neutron star. We
determine the secondary star's radial velocity semi-amplitude from the metallic
(primarily Fe and Ca) and Halpha absorption lines during these different
states. The metallic and Halpha radial velocity semi-amplitude determined from
the 2009 pulsar-state observations allows us to constrain the secondary star's
true radial velocity K_2=276.3+/-5.6 km/s and the binary mass ratio
q=0.137+/-0.003. By comparing the observed metallic and Halpha absorption-line
radial velocity semi-amplitudes with model predictions, we can explain the
observed semi-amplitude changes during the pulsar-state and during the
pulsar/disc-state transition as being due to different amounts of heating and
the presence of an accretion disc, respectively.
