xref: /dokuwiki/inc/Search/Collection/PageTitleCollection.php (revision 9369b4a991666bc911474806b106d8958e79f4c1)
1<?php
2
3namespace dokuwiki\Search\Collection;
4
5use dokuwiki\Search\Index\AbstractIndex;
6use dokuwiki\Search\Index\FileIndex;
7
8/**
9 * Collection for page titles
10 *
11 * Stores the title of each page as a direct 1:1 mapping.
12 *
13 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
14 * @author Andreas Gohr <andi@splitbrain.org>
15 */
16class PageTitleCollection extends DirectCollection
17{
18    /** @inheritdoc */
19    public function __construct(?AbstractIndex $pageIndex = null)
20    {
21        parent::__construct($pageIndex ?? 'page', 'title');
22    }
23
24    /**
25     * Use FileIndex for titles since each page has exactly one title
26     * accessed by RID — no need to load the entire index into memory
27     *
28     * @inheritdoc
29     */
30    public function getTokenIndex(int $group = 0): AbstractIndex
31    {
32        if ($this->idxToken instanceof AbstractIndex) {
33            return $this->idxToken;
34        }
35        return new FileIndex($this->idxToken, '', $this->isWritable);
36    }
37}
38