mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-25 05:22:59 +00:00
Add json support to search action! :D
This commit is contained in:
parent
c355c89b30
commit
90acf38f9d
9 changed files with 143 additions and 84 deletions
|
@ -6,6 +6,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
|
|||
### Added
|
||||
- [Rest API] Added support for the `mode` parameter to the `random` action.
|
||||
- Fixed various issues with both the module api & the rest api docs.
|
||||
- Add json support to search action :D
|
||||
|
||||
### Fixed
|
||||
- Properly escaped content of short code box on file pages
|
||||
|
|
|
@ -500,6 +500,9 @@ if($env->is_logged_in)
|
|||
////////////////////
|
||||
// APIDoc strings //
|
||||
////////////////////
|
||||
/**
|
||||
* @apiDefine Admin Only the wiki administrator may use this call.
|
||||
*/
|
||||
/**
|
||||
* @apiDefine Moderator Only users loggged with a moderator account may use this call.
|
||||
*/
|
||||
|
@ -2267,12 +2270,12 @@ register_module([
|
|||
"code" => function() {
|
||||
global $settings;
|
||||
/**
|
||||
* @api {get} ?action=random Redirects to a random page.
|
||||
* @apiName RawSource
|
||||
* @api {get} ?action=random[&mode={modeName}] Redirects to a random page
|
||||
* @apiName Random
|
||||
* @apiGroup Page
|
||||
* @apiPermission Anonymous
|
||||
*
|
||||
* @apiParam {string} mode The view mode to redirect to. This parameter is basically just passed through to the direct - it works in the same way as the mode parameter on the _view_ action does.
|
||||
* @apiParam {string} mode The view mode to redirect to. This parameter is basically just passed through to the direct. It works in the same way as the mode parameter on the view action does.
|
||||
*/
|
||||
|
||||
add_action("random", function() {
|
||||
|
@ -3596,7 +3599,7 @@ register_module([
|
|||
|
||||
register_module([
|
||||
"name" => "Search",
|
||||
"version" => "0.6.1",
|
||||
"version" => "0.6.2",
|
||||
"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.",
|
||||
"id" => "feature-search",
|
||||
|
@ -3608,6 +3611,7 @@ register_module([
|
|||
* @apiName SearchIndex
|
||||
* @apiGroup Search
|
||||
* @apiPermission Anonymous
|
||||
* @apiDescription For debugging purposes. Be warned - the format could change at any time!
|
||||
*
|
||||
* @apiParam {string} page The page to generate a word index page.
|
||||
*/
|
||||
|
@ -3690,12 +3694,13 @@ register_module([
|
|||
});
|
||||
|
||||
/**
|
||||
* @api {get} ?action=search&query={text} Search the wiki for a given query string
|
||||
* @api {get} ?action=search&query={text}[&format={format}] Search the wiki for a given query string
|
||||
* @apiName Search
|
||||
* @apiGroup Search
|
||||
* @apiPermission Anonymous
|
||||
*
|
||||
* @apiParam {string} query The query string to search for.
|
||||
* @apiParam {string} format Optional. Valid values: html, json. In json mode an object is returned with page names as keys, values as search result information - sorted in ranking order.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -3722,6 +3727,20 @@ register_module([
|
|||
$results = search::query_invindex($_GET["query"], $invindex);
|
||||
$resultCount = count($results);
|
||||
|
||||
foreach($results as &$result) {
|
||||
$result["context"] = search::extract_context(
|
||||
$_GET["query"],
|
||||
file_get_contents($env->storage_prefix . $result["pagename"] . ".md")
|
||||
);
|
||||
}
|
||||
|
||||
if(!empty($_GET["format"]) && $_GET["format"] == "json") {
|
||||
header("content-type: application/json");
|
||||
$json_results = new stdClass();
|
||||
foreach($results as $result) $json_results->{$result["pagename"]} = $result;
|
||||
exit(json_encode($json_results));
|
||||
}
|
||||
|
||||
$env->perfdata->search_time = round((microtime(true) - $search_start)*1000, 3);
|
||||
|
||||
$title = $_GET["query"] . " - Search results - $settings->sitename";
|
||||
|
@ -3788,7 +3807,7 @@ register_module([
|
|||
$pagesource = file_get_contents($env->storage_prefix . $result["pagename"] . ".md");
|
||||
|
||||
//echo("Extracting context for result " . $result["pagename"] . ".\n");
|
||||
$context = search::extract_context($_GET["query"], $pagesource);
|
||||
$context = $result["context"];
|
||||
if(strlen($context) === 0)
|
||||
$context = substr($pagesource, 0, $settings->search_characters_context * 2);
|
||||
//echo("'Generated search context for " . $result["pagename"] . ": $context'\n");
|
||||
|
@ -3914,7 +3933,7 @@ register_module([
|
|||
|
||||
|
||||
/**
|
||||
* @api {get} ?action=suggest-pages[&type={type}] Get search suggestions for a query
|
||||
* @api {get} ?action=suggest-pages[&type={type}] Get page name suggestions for a query
|
||||
* @apiName OpenSearchDescription
|
||||
* @apiGroup Search
|
||||
* @apiPermission Anonymous
|
||||
|
|
3
core.php
3
core.php
|
@ -124,6 +124,9 @@ if($env->is_logged_in)
|
|||
////////////////////
|
||||
// APIDoc strings //
|
||||
////////////////////
|
||||
/**
|
||||
* @apiDefine Admin Only the wiki administrator may use this call.
|
||||
*/
|
||||
/**
|
||||
* @apiDefine Moderator Only users loggged with a moderator account may use this call.
|
||||
*/
|
||||
|
|
|
@ -584,6 +584,36 @@ define({ "api": [
|
|||
"filename": "./modules/action-protect.php",
|
||||
"groupTitle": "Page"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "?action=random[&mode={modeName}]",
|
||||
"title": "Redirects to a random page",
|
||||
"name": "Random",
|
||||
"group": "Page",
|
||||
"permission": [
|
||||
{
|
||||
"name": "Anonymous",
|
||||
"title": "Anybody may use this call.",
|
||||
"description": ""
|
||||
}
|
||||
],
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "mode",
|
||||
"description": "<p>The view mode to redirect to. This parameter is basically just passed through to the direct. It works in the same way as the mode parameter on the view action does.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./modules/action-random.php",
|
||||
"groupTitle": "Page"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "?action=raw&page={pageName}",
|
||||
|
@ -614,36 +644,6 @@ define({ "api": [
|
|||
"filename": "./modules/action-raw.php",
|
||||
"groupTitle": "Page"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "?action=random[&mode={mode}]",
|
||||
"title": "Redirects to a random page.",
|
||||
"name": "RawSource",
|
||||
"group": "Page",
|
||||
"permission": [
|
||||
{
|
||||
"name": "Anonymous",
|
||||
"title": "Anybody may use this call.",
|
||||
"description": ""
|
||||
}
|
||||
],
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "mode",
|
||||
"description": "<p>The view mode to redirect to. This parameter is basically just passed through to the direct - it works in the same way as the mode parameter on the <em>view</em> action does.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./modules/action-random.php",
|
||||
"groupTitle": "Page"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "?action=raw&page={pageName}",
|
||||
|
@ -739,7 +739,7 @@ define({ "api": [
|
|||
{
|
||||
"type": "get",
|
||||
"url": "?action=suggest-pages[&type={type}]",
|
||||
"title": "Get search suggestions for a query",
|
||||
"title": "Get page name suggestions for a query",
|
||||
"name": "OpenSearchDescription",
|
||||
"group": "Search",
|
||||
"permission": [
|
||||
|
@ -792,7 +792,7 @@ define({ "api": [
|
|||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "?action=search&query={text}",
|
||||
"url": "?action=search&query={text}[&format={format}]",
|
||||
"title": "Search the wiki for a given query string",
|
||||
"name": "Search",
|
||||
"group": "Search",
|
||||
|
@ -812,6 +812,13 @@ define({ "api": [
|
|||
"optional": false,
|
||||
"field": "query",
|
||||
"description": "<p>The query string to search for.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "format",
|
||||
"description": "<p>Optional. Valid values: html, json. In json mode an object is returned with page names as keys, values as search result information - sorted in ranking order.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -863,6 +870,7 @@ define({ "api": [
|
|||
"description": ""
|
||||
}
|
||||
],
|
||||
"description": "<p>For debugging purposes. Be warned - the format could change at any time!</p>",
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
|
@ -889,7 +897,9 @@ define({ "api": [
|
|||
"group": "Search",
|
||||
"permission": [
|
||||
{
|
||||
"name": "Admin"
|
||||
"name": "Admin",
|
||||
"title": "Only the wiki administrator may use this call.",
|
||||
"description": ""
|
||||
}
|
||||
],
|
||||
"parameter": {
|
||||
|
|
|
@ -584,6 +584,36 @@
|
|||
"filename": "./modules/action-protect.php",
|
||||
"groupTitle": "Page"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "?action=random[&mode={modeName}]",
|
||||
"title": "Redirects to a random page",
|
||||
"name": "Random",
|
||||
"group": "Page",
|
||||
"permission": [
|
||||
{
|
||||
"name": "Anonymous",
|
||||
"title": "Anybody may use this call.",
|
||||
"description": ""
|
||||
}
|
||||
],
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "mode",
|
||||
"description": "<p>The view mode to redirect to. This parameter is basically just passed through to the direct. It works in the same way as the mode parameter on the view action does.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./modules/action-random.php",
|
||||
"groupTitle": "Page"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "?action=raw&page={pageName}",
|
||||
|
@ -614,36 +644,6 @@
|
|||
"filename": "./modules/action-raw.php",
|
||||
"groupTitle": "Page"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "?action=random[&mode={mode}]",
|
||||
"title": "Redirects to a random page.",
|
||||
"name": "RawSource",
|
||||
"group": "Page",
|
||||
"permission": [
|
||||
{
|
||||
"name": "Anonymous",
|
||||
"title": "Anybody may use this call.",
|
||||
"description": ""
|
||||
}
|
||||
],
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "mode",
|
||||
"description": "<p>The view mode to redirect to. This parameter is basically just passed through to the direct - it works in the same way as the mode parameter on the <em>view</em> action does.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"filename": "./modules/action-random.php",
|
||||
"groupTitle": "Page"
|
||||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "?action=raw&page={pageName}",
|
||||
|
@ -739,7 +739,7 @@
|
|||
{
|
||||
"type": "get",
|
||||
"url": "?action=suggest-pages[&type={type}]",
|
||||
"title": "Get search suggestions for a query",
|
||||
"title": "Get page name suggestions for a query",
|
||||
"name": "OpenSearchDescription",
|
||||
"group": "Search",
|
||||
"permission": [
|
||||
|
@ -792,7 +792,7 @@
|
|||
},
|
||||
{
|
||||
"type": "get",
|
||||
"url": "?action=search&query={text}",
|
||||
"url": "?action=search&query={text}[&format={format}]",
|
||||
"title": "Search the wiki for a given query string",
|
||||
"name": "Search",
|
||||
"group": "Search",
|
||||
|
@ -812,6 +812,13 @@
|
|||
"optional": false,
|
||||
"field": "query",
|
||||
"description": "<p>The query string to search for.</p>"
|
||||
},
|
||||
{
|
||||
"group": "Parameter",
|
||||
"type": "string",
|
||||
"optional": false,
|
||||
"field": "format",
|
||||
"description": "<p>Optional. Valid values: html, json. In json mode an object is returned with page names as keys, values as search result information - sorted in ranking order.</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -863,6 +870,7 @@
|
|||
"description": ""
|
||||
}
|
||||
],
|
||||
"description": "<p>For debugging purposes. Be warned - the format could change at any time!</p>",
|
||||
"parameter": {
|
||||
"fields": {
|
||||
"Parameter": [
|
||||
|
@ -889,7 +897,9 @@
|
|||
"group": "Search",
|
||||
"permission": [
|
||||
{
|
||||
"name": "Admin"
|
||||
"name": "Admin",
|
||||
"title": "Only the wiki administrator may use this call.",
|
||||
"description": ""
|
||||
}
|
||||
],
|
||||
"parameter": {
|
||||
|
|
|
@ -8,7 +8,7 @@ define({
|
|||
"apidoc": "0.3.0",
|
||||
"generator": {
|
||||
"name": "apidoc",
|
||||
"time": "2018-02-14T22:36:20.697Z",
|
||||
"time": "2018-02-14T23:07:15.949Z",
|
||||
"url": "http://apidocjs.com",
|
||||
"version": "0.17.6"
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"apidoc": "0.3.0",
|
||||
"generator": {
|
||||
"name": "apidoc",
|
||||
"time": "2018-02-14T22:36:20.697Z",
|
||||
"time": "2018-02-14T23:07:15.949Z",
|
||||
"url": "http://apidocjs.com",
|
||||
"version": "0.17.6"
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
"author": "Starbeamrainbowlabs",
|
||||
"description": "Adds an action called 'random' that redirects you to a random page.",
|
||||
"id": "action-random",
|
||||
"lastupdate": 1518647615,
|
||||
"lastupdate": 1518648324,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
|
@ -100,11 +100,11 @@
|
|||
},
|
||||
{
|
||||
"name": "Search",
|
||||
"version": "0.6.1",
|
||||
"version": "0.6.2",
|
||||
"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.",
|
||||
"id": "feature-search",
|
||||
"lastupdate": 1517752177,
|
||||
"lastupdate": 1518649628,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
register_module([
|
||||
"name" => "Search",
|
||||
"version" => "0.6.1",
|
||||
"version" => "0.6.2",
|
||||
"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.",
|
||||
"id" => "feature-search",
|
||||
|
@ -13,6 +13,7 @@ register_module([
|
|||
* @apiName SearchIndex
|
||||
* @apiGroup Search
|
||||
* @apiPermission Anonymous
|
||||
* @apiDescription For debugging purposes. Be warned - the format could change at any time!
|
||||
*
|
||||
* @apiParam {string} page The page to generate a word index page.
|
||||
*/
|
||||
|
@ -95,12 +96,13 @@ register_module([
|
|||
});
|
||||
|
||||
/**
|
||||
* @api {get} ?action=search&query={text} Search the wiki for a given query string
|
||||
* @api {get} ?action=search&query={text}[&format={format}] Search the wiki for a given query string
|
||||
* @apiName Search
|
||||
* @apiGroup Search
|
||||
* @apiPermission Anonymous
|
||||
*
|
||||
* @apiParam {string} query The query string to search for.
|
||||
* @apiParam {string} format Optional. Valid values: html, json. In json mode an object is returned with page names as keys, values as search result information - sorted in ranking order.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -127,6 +129,20 @@ register_module([
|
|||
$results = search::query_invindex($_GET["query"], $invindex);
|
||||
$resultCount = count($results);
|
||||
|
||||
foreach($results as &$result) {
|
||||
$result["context"] = search::extract_context(
|
||||
$_GET["query"],
|
||||
file_get_contents($env->storage_prefix . $result["pagename"] . ".md")
|
||||
);
|
||||
}
|
||||
|
||||
if(!empty($_GET["format"]) && $_GET["format"] == "json") {
|
||||
header("content-type: application/json");
|
||||
$json_results = new stdClass();
|
||||
foreach($results as $result) $json_results->{$result["pagename"]} = $result;
|
||||
exit(json_encode($json_results));
|
||||
}
|
||||
|
||||
$env->perfdata->search_time = round((microtime(true) - $search_start)*1000, 3);
|
||||
|
||||
$title = $_GET["query"] . " - Search results - $settings->sitename";
|
||||
|
@ -193,7 +209,7 @@ register_module([
|
|||
$pagesource = file_get_contents($env->storage_prefix . $result["pagename"] . ".md");
|
||||
|
||||
//echo("Extracting context for result " . $result["pagename"] . ".\n");
|
||||
$context = search::extract_context($_GET["query"], $pagesource);
|
||||
$context = $result["context"];
|
||||
if(strlen($context) === 0)
|
||||
$context = substr($pagesource, 0, $settings->search_characters_context * 2);
|
||||
//echo("'Generated search context for " . $result["pagename"] . ": $context'\n");
|
||||
|
@ -319,7 +335,7 @@ register_module([
|
|||
|
||||
|
||||
/**
|
||||
* @api {get} ?action=suggest-pages[&type={type}] Get search suggestions for a query
|
||||
* @api {get} ?action=suggest-pages[&type={type}] Get page name suggestions for a query
|
||||
* @apiName OpenSearchDescription
|
||||
* @apiGroup Search
|
||||
* @apiPermission Anonymous
|
||||
|
|
Loading…
Reference in a new issue