Browse Source

implement manifest API

main
ghost 2 years ago
parent
commit
a2fc14c8cf
  1. 16
      README.md
  2. 20
      config/app.php.txt
  3. 61
      public/api.php
  4. 3
      public/index.php

16
README.md

@ -51,7 +51,7 @@ Could be enabled or disabled by `API_ENABLED` option @@ -51,7 +51,7 @@ Could be enabled or disabled by `API_ENABLED` option
/api.php
```
##### Search API
##### Search
Returns search results.
@ -65,7 +65,7 @@ GET query={string} - optional, search request, empty if not provided @@ -65,7 +65,7 @@ GET query={string} - optional, search request, empty if not provided
GET page={int} - optional, search results page, 1 if not provided
```
##### Hosts distribution API
##### Hosts distribution
Returns node hosts collected with fields provided in `API_HOSTS_FIELDS` option.
@ -77,6 +77,18 @@ Could be enabled or disabled by `API_HOSTS_ENABLED` option @@ -77,6 +77,18 @@ Could be enabled or disabled by `API_HOSTS_ENABLED` option
GET action=hosts - required
```
##### Application manifest
Returns node information.
Could be enabled or disabled by `API_MANIFEST_ENABLED` option
###### Request attributes
```
GET action=manifest - required
```
#### Roadmap / ideas
* [x] Web pages full text ranking search

20
config/app.php.txt

@ -5,6 +5,16 @@ ini_set('display_errors', '1'); @@ -5,6 +5,16 @@ ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
// Application
/*
* Unique project name
*
* using to ident the app in the YGGo ecosystem
*
*/
define('APPLICATION_NAME', 'My YGGo host');
// Website
/*
@ -200,3 +210,13 @@ define('API_HOSTS_FIELDS', @@ -200,3 +210,13 @@ define('API_HOSTS_FIELDS',
`host`.`timeAdded`,
`host`.`timeUpdated`,
(SELECT COUNT(*) FROM `hostPage` WHERE `hostPage`.`hostId` = `host`.`hostId`) AS `hostPagesTotal`'); // string: *|field names comma separated
/*
* Manifest API
*
* Application meta sharing between YGGo remote nodes
*
* When true - make this node public for distributed index sharing
*
*/
define('API_MANIFEST_ENABLED', true);

61
public/api.php

@ -1,5 +1,8 @@ @@ -1,5 +1,8 @@
<?php
// Current version
define('API_VERSION', 0.1);
// Load system dependencies
require_once('../config/app.php');
require_once('../library/curl.php');
@ -17,6 +20,8 @@ if (API_ENABLED) { @@ -17,6 +20,8 @@ if (API_ENABLED) {
// Search API
case 'search';
if (API_SEARCH_ENABLED) {
// Connect database
$db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD);
@ -52,11 +57,21 @@ if (API_ENABLED) { @@ -52,11 +57,21 @@ if (API_ENABLED) {
'result' => $dbResults,
];
} else {
$response = [
'status' => false,
'result' => [],
];
}
break;
// Host API
case 'hosts';
if (API_HOSTS_ENABLED) {
// Connect database
$db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD);
@ -66,6 +81,52 @@ if (API_ENABLED) { @@ -66,6 +81,52 @@ if (API_ENABLED) {
'result' => $db->getAPIHosts(API_HOSTS_FIELDS),
];
} else {
$response = [
'status' => false,
'result' => [],
];
}
break;
// Manifest API
case 'manifest';
if (API_MANIFEST_ENABLED) {
$response = [
'status' => true,
'result' => [
'APPLICATION_NAME' => APPLICATION_NAME,
'WEBSITE_DOMAIN' => WEBSITE_DOMAIN,
'CRAWL_URL_REGEXP' => CRAWL_URL_REGEXP,
'CRAWL_HOST_DEFAULT_PAGES_LIMIT' => CRAWL_HOST_DEFAULT_PAGES_LIMIT,
'CRAWL_HOST_DEFAULT_STATUS' => CRAWL_HOST_DEFAULT_STATUS,
'CRAWL_HOST_DEFAULT_META_ONLY' => CRAWL_HOST_DEFAULT_META_ONLY,
'CRAWL_ROBOTS_DEFAULT_RULES' => CRAWL_ROBOTS_DEFAULT_RULES,
'CRAWL_ROBOTS_POSTFIX_RULES' => CRAWL_ROBOTS_POSTFIX_RULES,
'CLEAN_HOST_SECONDS_OFFSET' => CLEAN_HOST_SECONDS_OFFSET,
'API_VERSION' => API_VERSION,
'API_ENABLED' => API_ENABLED,
'API_SEARCH_ENABLED' => API_SEARCH_ENABLED,
'API_HOSTS_ENABLED' => API_HOSTS_ENABLED,
],
];
} else {
$response = [
'status' => false,
'result' => [],
];
}
break;
default:

3
public/index.php

@ -21,6 +21,9 @@ $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the @@ -21,6 +21,9 @@ $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the
<head>
<title><?php echo _('YGGo! Web Search Engine') ?></title>
<meta charset="utf-8" />
<?php if (API_MANIFEST_ENABLED) { ?>
<meta name="yggo" content="<?php echo sprintf('%s/api.php?action=manifest', WEBSITE_DOMAIN) ?>" />
<?php } ?>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="<?php echo _('Javascript-less Open Source Web Search Engine') ?>" />
<meta name="keywords" content="<?php echo _('web, search, engine, crawler, php, pdo, mysql, sphinx, yggdrasil, js-less, open source') ?>" />

Loading…
Cancel
Save