How to refactor that content_tag adding method?
Just use variables for repeated expressions:

def set_caption(result)
  type_div = content_tag(:div, result.type_name, class: 'type-name') 
  if result.respond_to?(:app_name)
    type_div + content_tag(:div, result.app_name, class: 'app-name')
  else
    type_div
  end
end


Note that you can move the conditional further in: type_div + (condition ? app_div : ""). Use this style whenever this adds readibility (here I'd say it doesn't).