/
PageIndex.php
62 lines (50 loc) · 1.68 KB
/
PageIndex.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
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Concrete\Core\Page\Search\Index;
use Concrete\Core\Application\ApplicationAwareInterface;
use Concrete\Core\Application\ApplicationAwareTrait;
use Concrete\Core\Attribute\Category\PageCategory;
use Concrete\Core\Attribute\Key\SearchIndexer\SearchIndexerInterface;
use Concrete\Core\Entity\Attribute\Key\PageKey;
use Concrete\Core\Search\Index\AbstractIndex;
use Concrete\Core\Search\Index\Driver\IndexingDriverInterface;
use Concrete\Core\Search\Index\Driver\SearchingDriverInterface;
class PageIndex extends AbstractIndex implements ApplicationAwareInterface
{
use ApplicationAwareTrait;
/**
* PageIndex constructor.
* Doesn't require any constructor arguments
*/
public function __construct()
{
}
/**
* @return DefaultPageDriver|IndexingDriverInterface
*/
protected function getIndexer()
{
if (!$this->indexDriver) {
$this->indexDriver = $this->app[PageIndexer::class];
}
return $this->indexDriver;
}
/**
* Clear out all indexed items
* @return void
*/
public function clear()
{
/** @var PageCategory $pageCategory */
$pageCategory = $this->app[PageCategory::class];
/** @var PageKey $key */
foreach ($pageCategory->getList() as $key) {
/** @var SearchIndexerInterface $indexer */
$indexer = $key->getSearchIndexer();
// Update the key tables
$indexer->updateSearchIndexKeyColumns($pageCategory, $key);
}
// Truncate the existing search index
$database = $this->app['database']->connection();
$database->Execute('truncate table PageSearchIndex');
}
}