diff --git a/inc/pagequery.php b/inc/pagequery.php index 8b25b55..7650d8f 100644 --- a/inc/pagequery.php +++ b/inc/pagequery.php @@ -831,6 +831,53 @@ function page_search($query) { $result = array_keys(ft_pageSearch($query, $highlight)); return $result; } + + + /** + * use regex to search all page content + * + * @param $query + * @param $incl_ns + * @param $excl_ns + * @return mixed + */ + function page_search_regex($query, $incl_ns, $excl_ns) { + + $query = trim($query); + $pages = idx_get_indexer()->getPages(); + + // first deal with excluded namespaces, then included, order matters! + $pages = $this->_filter_ns($pages, $excl_ns, true); + $pages = $this->_filter_ns($pages, $incl_ns, false); + + $cnt = count($pages); + for ($i = 0; $i < $cnt; $i++) { + $page = $pages[$i]; + + $text = io_readFile(wikiFN($page, '', false), false); + + $matched = preg_match('/' . $query . '/iS', $text); + if ($matched === false) { + return false; + } elseif ($matched == 0) { + unset($pages[$i]); + } + } + + foreach($pages as $key => $page) { + if ( ! page_exists($page) || isHiddenPage($page)) { + unset($pages[$key]); + } + } + + if (count($pages) > 0) { + return $pages; + } else { + // we always return an array type + return array(); + } + } + /** @@ -841,7 +888,7 @@ function page_lookup($query, $fullregex, $incl_ns, $excl_ns) { global $conf; $query = trim($query); - $pages = file($conf['indexdir'] . '/page.idx'); + $pages = idx_get_indexer()->getPages(); if ( ! $fullregex) { // first deal with excluded namespaces, then included, order matters! @@ -864,7 +911,7 @@ function page_lookup($query, $fullregex, $incl_ns, $excl_ns) { * and the page-exists check above * The @ prevents problems with invalid queries! */ - $matched = @preg_match('/' . $query . '/i', $page); + $matched = @preg_match('/' . $query . '/iS', $page); if ($matched === false) { return false; } elseif ($matched == 0) { diff --git a/res/toolbar b/res/toolbar index 7017ad8..bcf1662 100644 --- a/res/toolbar +++ b/res/toolbar @@ -1,6 +1,7 @@ pagequery> * | .* | exclude ns: ^ |-ns: | include ns: @ | ns: | . | .. | text | regex fulltext Full-text search of page content fullregex Search the full page id using regex +fulltextregex Full-text search of page content using regex sort=column:direction Keys to sort by, in order of sorting - a, ab, abc By 1st letter, 2-letters, or 3-letters - name, pagename By page name [not grouped] diff --git a/syntax.php b/syntax.php index de1b548..c043497 100644 --- a/syntax.php +++ b/syntax.php @@ -76,6 +76,7 @@ function handle($match, $state, $pos, Doku_Handler $handler) { $opt['fontsize'] = ''; // base fontsize of pagequery; best to use % $opt['fullregex'] = false; // power-user regex search option--file name only $opt['fulltext'] = false; // search full-text; including file contents + $opt['fulltextregex'] = false; // search full-text; including file contents, using preg_match $opt['group'] = false; // group the results based on sort headings $opt['hidejump'] = false; // hide the jump to top link $opt['hidemsg'] = false; // hide any error messages @@ -99,6 +100,7 @@ function handle($match, $state, $pos, Doku_Handler $handler) { case 'casesort': case 'fullregex': case 'fulltext': + case 'fulltextregex': case 'group': case 'hidejump': case 'hidemsg': @@ -272,8 +274,14 @@ function render($mode, Doku_Renderer $renderer, $opt) { if ($query == '*') { $query = '.*'; } - // search by page name or path only - $results = $pq->page_lookup($query, $opt['fullregex'], $incl_ns, $excl_ns); + + if($opt['fulltextregex'] == true) { + // search by page name or path only + $results = $pq->page_search_regex($query, $incl_ns, $excl_ns); + } else { + // search by page name or path only + $results = $pq->page_lookup($query, $opt['fullregex'], $incl_ns, $excl_ns); + } } $results = $pq->validate_pages($results, $opt['hidestart'], $opt['maxns']);