3 namespace dokuwiki\Action
;
5 use dokuwiki\Action\Exception\ActionAbort
;
10 * Search for pages and content
12 * @package dokuwiki\Action
14 class Search
extends AbstractAction
{
16 protected $pageLookupResults = array();
17 protected $fullTextResults = array();
18 protected $highlight = array();
21 public function minimumPermission() {
26 * we only search if a search word was given
30 public function checkPermissions() {
31 parent
::checkPermissions();
34 public function preProcess()
36 global $QUERY, $ID, $conf, $INPUT;
39 if ($ID !== $conf['start'] && $s === '') {
40 parse_str($INPUT->server
->str('QUERY_STRING'), $urlParts);
41 $urlParts['q'] = $urlParts['id'];
42 $urlParts['id'] = $conf['start'];
43 $url = DOKU_URL
. DOKU_SCRIPT
. '?' . http_build_query($urlParts, null, '&');
47 if ($s === '') throw new ActionAbort();
48 $this->adjustGlobalQuery();
52 public function tplContent()
56 $search = new \dokuwiki\Ui\
Search($this->pageLookupResults
, $this->fullTextResults
, $this->highlight
);
64 protected function execute()
66 global $INPUT, $QUERY;
67 $this->pageLookupResults
= ft_pageLookup($QUERY, true, useHeading('navigation'));
68 $this->fullTextResults
= ft_pageSearch($QUERY, $highlight, $INPUT->str('sort'));
69 $this->highlight
= $highlight;
73 * Adjust the global query accordingly to the config search_limit_to_first_ns and search_default_fragment_behaviour
75 * This will only do something if the search didn't originate from the form on the searchpage itself
77 protected function adjustGlobalQuery()
79 global $conf, $INPUT, $QUERY, $ID;
81 if ($INPUT->bool('searchPageForm')) {
85 $Indexer = idx_get_indexer();
86 $parsedQuery = ft_queryParser($Indexer, $QUERY);
88 if (empty($parsedQuery['ns']) && empty($parsedQuery['notns'])) {
89 if ($conf['search_limit_to_first_ns'] > 0) {
90 if (getNS($ID) !== false) {
91 $nsParts = explode(':', getNS($ID));
92 $ns = implode(':', array_slice($nsParts, 0, $conf['search_limit_to_first_ns']));
98 if ($conf['search_default_fragment_behaviour'] !== 'exact') {
99 if (empty(array_diff($parsedQuery['words'], $parsedQuery['and']))) {
100 if (strpos($QUERY, '*') === false) {
101 $queryParts = explode(' ', $QUERY);
102 $queryParts = array_map(function ($part) {
103 if (strpos($part, '@') === 0) {
106 if (strpos($part, 'ns:') === 0) {
109 if (strpos($part, '^') === 0) {
112 if (strpos($part, '-ns:') === 0) {
118 if ($conf['search_default_fragment_behaviour'] === 'starts_with') {
121 if ($conf['search_default_fragment_behaviour'] === 'ends_with') {
125 return '*' . $part . '*';
128 $QUERY = implode(' ', $queryParts);