aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--_test/tests/inc/FulltextPageLookupTest.php22
-rw-r--r--inc/fulltext.php11
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