I am attempting to add add a taxonomy value inside of TNTSearch result. Specifically, my search results show the Title and a Content snippet. I want to include a taxonomy in the search results. My frontmatter:
YAML
---title:TEST Documenttaxonomy:id:['dp-04']---
I want to include in my TNT Search Result: {{ val.taxonomy.id }}
I got this to work. See code for reference below. Note - I am only including the Taxonomy->ID field in the results. Code adjustment may be necessary to include other taxonomy.
PHP
publicfunctiononTNTSearchQuery(Event$e){$query=$e['query'];$page=$e['page'];$options=$e['options'];$fields=$e['fields'];$gtnt=$e['gtnt'];$tax=$page->taxonomy();if(!isset($tax['id'][0])){$id=$tax['id'][0]='';// set default value}else{$id=$tax['id'][0];}$content=$gtnt->getCleanContent($page);$title=$page->title();$relevant=$gtnt->tnt->snippet($query,$content,$options['snippet']);if(strlen($relevant)<=6){$relevant=substr($content,0,$options['snippet']);}$fields->hits[]=['link'=>$page->route(),'title'=>$gtnt->tnt->highlight($title,$query,'em',['wholeWord'=>false]),'content'=>$gtnt->tnt->highlight($relevant,$query,'em',['wholeWord'=>false]),'id'=>$gtnt->tnt->highlight($id,$query,'em',['wholeWord'=>false]),];$e->stopPropagation();}
Also, don't for get to call the onTNTSearchQuery function in the beginning.