-
Notifications
You must be signed in to change notification settings - Fork 4
/
functions.php
50 lines (38 loc) · 1.09 KB
/
functions.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
function getResults($algolia, $indexName, $query, $requestOptions = [])
{
$index = $algolia->initIndex($indexName);
return $index->search($query, $requestOptions)['hits'];
}
function getTitle($hit)
{
if (isset($hit['hierarchy']['lvl6'])) {
return [$hit['hierarchy']['lvl6'], 6];
}
if (isset($hit['hierarchy']['lvl5'])) {
return [$hit['hierarchy']['lvl5'], 5];
}
if (isset($hit['hierarchy']['lvl4'])) {
return [$hit['hierarchy']['lvl4'], 4];
}
if (isset($hit['hierarchy']['lvl3'])) {
return [$hit['hierarchy']['lvl3'], 3];
}
if (isset($hit['hierarchy']['lvl2'])) {
return [$hit['hierarchy']['lvl2'], 2];
}
if (isset($hit['hierarchy']['lvl1'])) {
return [$hit['hierarchy']['lvl1'], 1];
}
return [null, null];
}
function getSubtitle($hit, $titleLevel)
{
$currentLevel = 0;
$subtitle = $hit['hierarchy']['lvl0'];
while ($currentLevel < $titleLevel) {
$currentLevel++;
$subtitle .= ' » ' . $hit['hierarchy']['lvl' . $currentLevel];
}
return $subtitle;
}