diff options
author | Andreas Gohr <andi@splitbrain.org> | 2021-04-05 09:32:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-05 09:32:58 +0200 |
commit | f09650da93dc8014335b58b032330f549012d16b (patch) | |
tree | ceaccd09f2583c914fb8e7b6643b489ba98fe1e9 | |
parent | ccd2e0d6471f85289b4d142ea7bdd95d8edf03a2 (diff) | |
parent | 4756d8a39b35b287407ef0c5c62122ce5798bf4a (diff) | |
download | dokuwiki-f09650da93dc8014335b58b032330f549012d16b.tar.gz dokuwiki-f09650da93dc8014335b58b032330f549012d16b.zip |
Merge pull request #3456 from splitbrain/excludensinpagelookup
Exclude namespace in page look-ups
-rw-r--r-- | _test/tests/inc/FulltextPageLookupTest.php | 22 | ||||
-rw-r--r-- | inc/fulltext.php | 11 |
2 files changed, 33 insertions, 0 deletions
diff --git a/_test/tests/inc/FulltextPageLookupTest.php b/_test/tests/inc/FulltextPageLookupTest.php new file mode 100644 index 000000000..b0c98500b --- /dev/null +++ b/_test/tests/inc/FulltextPageLookupTest.php @@ -0,0 +1,22 @@ +<?php + +// must be run within Dokuwiki +if (!defined('DOKU_INC')) die(); + +/** + * Test cases search only in a namespace or exclude a namespace + */ +class FulltextPageLookupTest extends DokuWikiTest { + + public function test_inoutns() { + saveWikiText('test:page1', 'Some text', 'Test initialization'); + idx_addPage('test:page1'); + saveWikiText('ns:page2', 'Other text', 'Test initialization'); + idx_addPage('ns:page2'); + + $this->assertEquals(['test:page1' => null, 'ns:page2' => null], ft_pageLookup('page')); + $this->assertEquals(['test:page1' => null], ft_pageLookup('page @test')); + $this->assertEquals(['ns:page2' => null], ft_pageLookup('page ^test')); + } + +} diff --git a/inc/fulltext.php b/inc/fulltext.php index 5ed0fe76f..7c28a5962 100644 --- a/inc/fulltext.php +++ b/inc/fulltext.php @@ -268,6 +268,10 @@ function _ft_pageLookup(&$data){ $ns = cleanID($parsedQuery['ns'][0]) . ':'; $id = implode(' ', $parsedQuery['highlight']); } + if (count($parsedQuery['notns']) > 0) { + $notns = cleanID($parsedQuery['notns'][0]) . ':'; + $id = implode(' ', $parsedQuery['highlight']); + } $in_ns = $data['in_ns']; $in_title = $data['in_title']; @@ -299,6 +303,13 @@ function _ft_pageLookup(&$data){ } } } + if (isset($notns)) { + foreach (array_keys($pages) as $p_id) { + if (strpos($p_id, $notns) === 0) { + unset($pages[$p_id]); + } + } + } // discard hidden pages // discard nonexistent pages |