Apache Sorl Add Custom Term Indexing with Hierarchy
You don't need custom code to achieve this, quoting from here:


  There's a wonderful little checkbox in the Search API workflow tab
  which enables it.
  
  Head to:
  
  admin/config/search/search_api/index/your solr server/workflow
  
  (You'll need to have created a server to get to this.)
  
  And then tick the box "Index Hierarchy".
  
  In callback options select the taxonomy field where you would like
  searching for the parent to include the child.