Commit 539e4ae0 authored by Luke081515's avatar Luke081515

Merge branch 'search' into 'master'

Search

See merge request !77
parents 0c3da563 9c921261
Pipeline #1716 passed with stages
in 2 minutes and 38 seconds
......@@ -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
......
......@@ -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");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment