-
Notifications
You must be signed in to change notification settings - Fork 0
/
nova-search.php
31 lines (22 loc) · 765 Bytes
/
nova-search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
use Alfred\Workflows\Workflow;
use AlgoliaSearch\Client as Algolia;
require __DIR__ . '/vendor/autoload.php';
$query = $argv[1];
$workflow = new Workflow;
$algoliaClient = new Algolia('6EVZSN4WQD', 'bf1eceffbd547a1443da21aab145c2d5');
$index = $algoliaClient->initIndex('nova-docs-1.0');
$search = $index->search($query);
$results = $search['hits'];
foreach ($results as $hit) {
$title = strip_tags(html_entity_decode($hit['_highlightResult']['title']['value'], ENT_QUOTES, 'UTF-8'));
$workflow->result()
->uid($hit['objectID'])
->title($title)
->autocomplete($title)
->subtitle($hit['subtext'])
->arg($hit['url'])
->quicklookurl($hit['url'])
->valid(true);
}
echo $workflow->output();