My php skills are not enough to be able to tell where your issue is with your code. But another way to acheive the same effect is with component . Add a new component that include the fields that you want to display. Each of the matches from the search will use the component rendering to display the results.
Angryboy makes extensive use of components in his tutorials
Angryboy makes extensive use of components in his tutorials