Skip to content

Instantly share code, notes, and snippets.

@nticaric
Created April 13, 2016 15:41
Show Gist options
  • Save nticaric/269d26e2204d35a36c2047ac22bd30c4 to your computer and use it in GitHub Desktop.
Save nticaric/269d26e2204d35a36c2047ac22bd30c4 to your computer and use it in GitHub Desktop.
<?php
public function processResults($res, $request)
{
$data = ['hits' => [], 'nbHits' => count($res)];
foreach ($res as $result) {
$file = file_get_contents($result['path']);
$crawler = new Crawler;
$crawler->addHtmlContent($file);
$title = $crawler->filter('h1')->text();
$relevant = $this->tnt->snippet($request->get('query'), strip_tags($file));
$data['hits'][] = [
'link' => basename($result['path']),
'_highlightResult' => [
'h1' => [
'value' => $this->tnt->highlight($title, $request->get('query')),
],
'content' => [
'value' => $this->tnt->highlight($relevant, $request->get('query')),
]
]
];
}
return response()->json($data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment