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