diff --git a/BotCore.php b/BotCore.php index 5b3cb052a7523f5d556c07499f796affd92b4a78..eef4598d2166fd5fcf6e8fdc1e1748dd2651f003 100644 --- a/BotCore.php +++ b/BotCore.php @@ -1222,6 +1222,24 @@ class Core extends Password { $content = substr($content, 0, strpos($content, "=")); return ["title" => $content, "level" => $sectionlevel, ]; } + /** search + * uses API fulltext search + * @author KPFC / Luke081515 + * @param pattern - pattern to search + * @param ns - [default: 0] numbers of the namespaces to search in; seperate with "|" + * @param prop - [default: size|wordcount|timestamp|snippet] properties to return; seperate with "|" (size, wordcount, timestamp, snippet, titlesnippet, redirecttitle, redirectsnippet, sectiontitle, sectionsnippet, isfilematch, categorysnippet, extensiondata) + * @param limit - [default: 50] number of results to return; max 500 or 5000 for bots + * @param offset - [default: 0] show only the results from position on + * @param what - [default: text] what to search (title/text/nearmatch) + * @return result - array with the results + */ + public function search($pattern, $ns = 0, $prop = "size|wordcount|timestamp|snippet", $limit = 50, $offset = 0, $what = "text") { + $data = "action=query&format=json&assert=" + . $this->assert . "&maxlag=" . $this->maxlag . "&list=search&srsearch=" + . urlencode($pattern) . "&srnamespace=" . $ns . "&srprop=" . $prop . "&srlimit=" + . $limit . "&sroffset=" . $offset . "&srwhat=" . $what; + return json_decode($this->httpRequest($data, $this->job, "GET"), true); + } /** getMaxlag * @author Luke081515 * @return $this->maxlag diff --git a/Debug.php b/Debug.php index 554a1590c69f16ffc6d5da13576b78c404f0138b..b6ddd6ae77b4f642bdb720c4c65132df2092bf7b 100644 --- a/Debug.php +++ b/Debug.php @@ -528,6 +528,22 @@ class Debug extends Core { $this->processError($e, $starttime, $endtime); } break; + case 'search': + $required = array("pattern"); + $optional = array("ns", "prop", "limit", "offset", "what"); + $optvalues = array(0, "size|wordcount|timestamp|snippet", 50, 0, "text"); + $Param = $this->getParams($required, $optional, $optvalues); + $this->echoNotice('Starting the function call of search...'); + $starttime = microtime (true); + try { + $ret = $this->search($Param[0], $Param[1], $Param[2], $Param[3], $Param[4], $Param[5]); + $endtime = microtime (true); + $this->processFunction($ret, $starttime, $endtime, true); + } catch (Exception $e) { + $endtime = microtime (true); + $this->processError($e, $starttime, $endtime); + } + break; // Admin functions case 'deletePage': $required = array("title", "reason");