mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 04:23:01 +00:00
Add method to return raw search result information as json
This commit is contained in:
parent
d83bbb3527
commit
313bcc7edf
4 changed files with 99 additions and 3 deletions
|
@ -1044,7 +1044,7 @@ class ids
|
||||||
if($entry == $pagename)
|
if($entry == $pagename)
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This pagename doesn't have an id - assign it one quick!
|
// This pagename doesn't have an id - assign it one quick!
|
||||||
return self::assign($pagename);
|
return self::assign($pagename);
|
||||||
}
|
}
|
||||||
|
@ -2738,6 +2738,54 @@ register_module([
|
||||||
//var_dump($results);
|
//var_dump($results);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ██████ ██ ██ ███████ ██████ ██ ██
|
||||||
|
* ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
* ██ ██ ██ ██ █████ ██████ ████ █████
|
||||||
|
* ██ ▄▄ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
* ██████ ██████ ███████ ██ ██ ██
|
||||||
|
* ▀▀
|
||||||
|
* ███████ ███████ █████ ██████ ██████ ██ ██ ██ ███ ██ ██████ ███████ ██ ██
|
||||||
|
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██
|
||||||
|
* ███████ █████ ███████ ██████ ██ ███████ ██ ██ ██ ██ ██ ██ █████ ███
|
||||||
|
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
* ███████ ███████ ██ ██ ██ ██ ██████ ██ ██ ██ ██ ████ ██████ ███████ ██ ██
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {get} ?action=query-searchindex&query={text} Inspect the internals of the search results for a query
|
||||||
|
* @apiName Search
|
||||||
|
* @apiGroup Search
|
||||||
|
* @apiPermission Anonymous
|
||||||
|
*
|
||||||
|
* @apiParam {string} query The query string to search for.
|
||||||
|
*/
|
||||||
|
add_action("query-searchindex", function() {
|
||||||
|
global $env, $paths;
|
||||||
|
|
||||||
|
if(empty($_GET["query"])) {
|
||||||
|
http_response_code(400);
|
||||||
|
header("content-type: text/plain");
|
||||||
|
exit("Error: No query specified. Specify it with the 'query' GET parameter.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$env->perfdata->searchindex_decode_start = microtime(true);
|
||||||
|
$searchIndex = search::load_invindex($paths->searchindex);
|
||||||
|
$env->perfdata->searchindex_decode_time = (microtime(true) - $env->perfdata->searchindex_decode_start) * 1000;
|
||||||
|
$env->perfdata->searchindex_query_start = microtime(true);
|
||||||
|
$searchResults = search::query_invindex($_GET["query"], $searchIndex);
|
||||||
|
$env->perfdata->searchindex_query_time = (microtime(true) - $env->perfdata->searchindex_query_start) * 1000;
|
||||||
|
|
||||||
|
header("content-type: application/json");
|
||||||
|
$result = new stdClass();
|
||||||
|
$result->time_format = "ms";
|
||||||
|
$result->decode_time = $env->perfdata->searchindex_decode_time;
|
||||||
|
$result->query_time = $env->perfdata->searchindex_query_time;
|
||||||
|
$result->total_time = $result->decode_time + $result->query_time;
|
||||||
|
$result->search_results = $searchResults;
|
||||||
|
exit(json_encode($result, JSON_PRETTY_PRINT));
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ██████ ██████ ███████ ███ ██ ███████ ███████ █████ ██████ ██████ ██ ██
|
* ██████ ██████ ███████ ███ ██ ███████ ███████ █████ ██████ ██████ ██ ██
|
||||||
* ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
* ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
|
2
core.php
2
core.php
|
@ -723,7 +723,7 @@ class ids
|
||||||
if($entry == $pagename)
|
if($entry == $pagename)
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This pagename doesn't have an id - assign it one quick!
|
// This pagename doesn't have an id - assign it one quick!
|
||||||
return self::assign($pagename);
|
return self::assign($pagename);
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
|
"description": "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
|
||||||
"id": "feature-search",
|
"id": "feature-search",
|
||||||
"lastupdate": 1490302006,
|
"lastupdate": 1490303523,
|
||||||
"optional": false
|
"optional": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -193,6 +193,54 @@ register_module([
|
||||||
//var_dump($results);
|
//var_dump($results);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ██████ ██ ██ ███████ ██████ ██ ██
|
||||||
|
* ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
* ██ ██ ██ ██ █████ ██████ ████ █████
|
||||||
|
* ██ ▄▄ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
* ██████ ██████ ███████ ██ ██ ██
|
||||||
|
* ▀▀
|
||||||
|
* ███████ ███████ █████ ██████ ██████ ██ ██ ██ ███ ██ ██████ ███████ ██ ██
|
||||||
|
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██
|
||||||
|
* ███████ █████ ███████ ██████ ██ ███████ ██ ██ ██ ██ ██ ██ █████ ███
|
||||||
|
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
* ███████ ███████ ██ ██ ██ ██ ██████ ██ ██ ██ ██ ████ ██████ ███████ ██ ██
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {get} ?action=query-searchindex&query={text} Inspect the internals of the search results for a query
|
||||||
|
* @apiName Search
|
||||||
|
* @apiGroup Search
|
||||||
|
* @apiPermission Anonymous
|
||||||
|
*
|
||||||
|
* @apiParam {string} query The query string to search for.
|
||||||
|
*/
|
||||||
|
add_action("query-searchindex", function() {
|
||||||
|
global $env, $paths;
|
||||||
|
|
||||||
|
if(empty($_GET["query"])) {
|
||||||
|
http_response_code(400);
|
||||||
|
header("content-type: text/plain");
|
||||||
|
exit("Error: No query specified. Specify it with the 'query' GET parameter.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$env->perfdata->searchindex_decode_start = microtime(true);
|
||||||
|
$searchIndex = search::load_invindex($paths->searchindex);
|
||||||
|
$env->perfdata->searchindex_decode_time = (microtime(true) - $env->perfdata->searchindex_decode_start) * 1000;
|
||||||
|
$env->perfdata->searchindex_query_start = microtime(true);
|
||||||
|
$searchResults = search::query_invindex($_GET["query"], $searchIndex);
|
||||||
|
$env->perfdata->searchindex_query_time = (microtime(true) - $env->perfdata->searchindex_query_start) * 1000;
|
||||||
|
|
||||||
|
header("content-type: application/json");
|
||||||
|
$result = new stdClass();
|
||||||
|
$result->time_format = "ms";
|
||||||
|
$result->decode_time = $env->perfdata->searchindex_decode_time;
|
||||||
|
$result->query_time = $env->perfdata->searchindex_query_time;
|
||||||
|
$result->total_time = $result->decode_time + $result->query_time;
|
||||||
|
$result->search_results = $searchResults;
|
||||||
|
exit(json_encode($result, JSON_PRETTY_PRINT));
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ██████ ██████ ███████ ███ ██ ███████ ███████ █████ ██████ ██████ ██ ██
|
* ██████ ██████ ███████ ███ ██ ███████ ███████ █████ ██████ ██████ ██ ██
|
||||||
* ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
* ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
|
Loading…
Reference in a new issue