xref: /plugin/searchindex/helper.php (revision 4773e14500fce3dfff8e66d291ab9dd93ca4eeb4)
1*4773e145SAndreas Gohr<?php
2*4773e145SAndreas Gohr
3*4773e145SAndreas Gohruse dokuwiki\Extension\Plugin;
4*4773e145SAndreas Gohr
5*4773e145SAndreas Gohr/**
6*4773e145SAndreas Gohr * Helper component for searchindex plugin
7*4773e145SAndreas Gohr *
8*4773e145SAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
9*4773e145SAndreas Gohr * @author     Andreas Gohr <andi@splitbrain.org>
10*4773e145SAndreas Gohr */
11*4773e145SAndreas Gohrclass helper_plugin_searchindex extends Plugin
12*4773e145SAndreas Gohr{
13*4773e145SAndreas Gohr    /**
14*4773e145SAndreas Gohr     * Get list of all pages
15*4773e145SAndreas Gohr     *
16*4773e145SAndreas Gohr     * @return string[] List of page IDs
17*4773e145SAndreas Gohr     */
18*4773e145SAndreas Gohr    public function getPagelist(): array
19*4773e145SAndreas Gohr    {
20*4773e145SAndreas Gohr        global $conf;
21*4773e145SAndreas Gohr        $data = [];
22*4773e145SAndreas Gohr        search($data, $conf['datadir'], 'search_allpages', []);
23*4773e145SAndreas Gohr
24*4773e145SAndreas Gohr        return array_column($data, 'id');
25*4773e145SAndreas Gohr    }
26*4773e145SAndreas Gohr
27*4773e145SAndreas Gohr    /**
28*4773e145SAndreas Gohr     * Clear all index files
29*4773e145SAndreas Gohr     *
30*4773e145SAndreas Gohr     * @return bool True on success
31*4773e145SAndreas Gohr     */
32*4773e145SAndreas Gohr    public function clearIndex(): bool
33*4773e145SAndreas Gohr    {
34*4773e145SAndreas Gohr        $indexer = idx_get_indexer();
35*4773e145SAndreas Gohr        return $indexer->clear() !== false;
36*4773e145SAndreas Gohr    }
37*4773e145SAndreas Gohr
38*4773e145SAndreas Gohr    /**
39*4773e145SAndreas Gohr     * Index the given page
40*4773e145SAndreas Gohr     *
41*4773e145SAndreas Gohr     * We're doing basically the same as the real indexer but ignore the
42*4773e145SAndreas Gohr     * last index time here
43*4773e145SAndreas Gohr     *
44*4773e145SAndreas Gohr     * @param string $page Page ID to index
45*4773e145SAndreas Gohr     * @param bool $force Force reindexing even if page hasn't changed
46*4773e145SAndreas Gohr     * @return bool True on success
47*4773e145SAndreas Gohr     */
48*4773e145SAndreas Gohr    public function indexPage(string $page, bool $force = false): bool
49*4773e145SAndreas Gohr    {
50*4773e145SAndreas Gohr        if (!$page) {
51*4773e145SAndreas Gohr            return false;
52*4773e145SAndreas Gohr        }
53*4773e145SAndreas Gohr
54*4773e145SAndreas Gohr        return idx_addPage($page, false, $force) !== false;
55*4773e145SAndreas Gohr    }
56*4773e145SAndreas Gohr}
57