1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Firesphere\SolrSearch\Extensions; |
4
|
|
|
|
5
|
|
|
use Firesphere\SolrSearch\Indexes\BaseIndex; |
6
|
|
|
use LogicException; |
7
|
|
|
use SilverStripe\Control\Controller; |
8
|
|
|
use SilverStripe\Control\Director; |
9
|
|
|
use SilverStripe\Core\Extension; |
10
|
|
|
use SilverStripe\Dev\Debug; |
11
|
|
|
use Solarium\QueryType\Select\Result\Result; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class \Firesphere\SolrSearch\Extensions\BaseIndexExtension |
15
|
|
|
* |
16
|
|
|
* @property BaseIndex|BaseIndexExtension $owner |
17
|
|
|
*/ |
18
|
|
|
class BaseIndexExtension extends Extension |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param Result $results |
23
|
|
|
*/ |
24
|
3 |
|
public function onAfterSearch($results): void |
25
|
|
|
{ |
26
|
3 |
|
if ((Director::isDev() || Director::is_cli()) && Controller::curr()->getRequest()->getVar('debugquery')) { |
27
|
|
|
/** @var \Solarium\Component\Result\Debug\Result $result */ |
28
|
|
|
$result = $results->getDebug(); |
29
|
|
|
Debug::message("Query string:\n" . $result->getQueryString()); |
30
|
|
|
Debug::message("Parsed query:\n" . $result->getParsedQuery()); |
31
|
|
|
Debug::message("Query parser:\n" . $result->getQueryParser()); |
32
|
|
|
Debug::message('Explanation:'); |
33
|
|
|
Debug::dump($result->getExplain()); |
34
|
|
|
} |
35
|
3 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Generate a yml version of the init method indexes |
39
|
|
|
*/ |
40
|
|
|
public function initToYml(): void |
41
|
|
|
{ |
42
|
|
|
if (function_exists('yaml_emit')) { |
43
|
|
|
/** @var BaseIndex $owner */ |
44
|
|
|
$owner = $this->owner; |
45
|
|
|
$result = [ |
46
|
|
|
BaseIndex::class => [ |
47
|
|
|
$owner->getIndexName() => |
48
|
|
|
[ |
49
|
|
|
'Classes' => $owner->getClasses(), |
50
|
|
|
'FulltextFields' => array_values($owner->getFulltextFields()), |
51
|
|
|
'SortFields' => $owner->getSortFields(), |
52
|
|
|
'FilterFields' => $owner->getFilterFields(), |
53
|
|
|
'BoostedFields' => $owner->getBoostedFields(), |
54
|
|
|
'CopyFields' => $owner->getCopyFields(), |
55
|
|
|
'DefaultField' => $owner->getDefaultField(), |
56
|
|
|
'FacetFields' => $owner->getFacetFields(), |
57
|
|
|
] |
58
|
|
|
] |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
Debug::dump(yaml_emit($result)); |
62
|
|
|
|
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
throw new LogicException('yaml-emit PHP module missing'); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|