Merge pull request #3456 from splitbrain/excludensinpagelookup

Exclude namespace in page look-ups
This commit is contained in:
Andreas Gohr 2021-04-05 09:32:58 +02:00 committed by GitHub
commit f09650da93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

@ -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'));
}
}

View File

@ -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