fix(search): remove overlook from parameter
[dokuwiki.git] / inc / Action / Search.php
blob7f632727bebee64699dc3e213a6bd661565a18a6
1 <?php
3 namespace dokuwiki\Action;
5 use dokuwiki\Action\Exception\ActionAbort;
7 /**
8 * Class Search
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();
20 /** @inheritdoc */
21 public function minimumPermission() {
22 return AUTH_NONE;
25 /**
26 * we only search if a search word was given
28 * @inheritdoc
30 public function checkPermissions() {
31 parent::checkPermissions();
34 public function preProcess()
36 global $QUERY, $ID, $conf, $INPUT;
37 $s = cleanID($QUERY);
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, '&');
44 send_redirect($url);
47 if ($s === '') throw new ActionAbort();
48 $this->adjustGlobalQuery();
51 /** @inheritdoc */
52 public function tplContent()
54 $this->execute();
56 $search = new \dokuwiki\Ui\Search($this->pageLookupResults, $this->fullTextResults, $this->highlight);
57 $search->show();
61 /**
62 * run the search
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;
72 /**
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')) {
82 return;
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']));
93 $QUERY .= " @$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) {
104 return $part;
106 if (strpos($part, 'ns:') === 0) {
107 return $part;
109 if (strpos($part, '^') === 0) {
110 return $part;
112 if (strpos($part, '-ns:') === 0) {
113 return $part;
116 global $conf;
118 if ($conf['search_default_fragment_behaviour'] === 'starts_with') {
119 return $part . '*';
121 if ($conf['search_default_fragment_behaviour'] === 'ends_with') {
122 return '*' . $part;
125 return '*' . $part . '*';
127 }, $queryParts);
128 $QUERY = implode(' ', $queryParts);