diff --git a/README.md b/README.md index 1a9d242..089f9ee 100644 --- a/README.md +++ b/README.md @@ -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 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 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 diff --git a/config/app.php.txt b/config/app.php.txt index 25953fd..73a60bc 100644 --- a/config/app.php.txt +++ b/config/app.php.txt @@ -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 /* @@ -199,4 +209,14 @@ define('API_HOSTS_FIELDS', `host`.`robotsPostfix`, `host`.`timeAdded`, `host`.`timeUpdated`, - (SELECT COUNT(*) FROM `hostPage` WHERE `hostPage`.`hostId` = `host`.`hostId`) AS `hostPagesTotal`'); // string: *|field names comma separated \ No newline at end of file + (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); \ No newline at end of file diff --git a/public/api.php b/public/api.php index db39e3b..c4b356f 100644 --- a/public/api.php +++ b/public/api.php @@ -1,5 +1,8 @@ searchHostPagesTotal('"' . $query . '"'); - $sphinxResults = $sphinx->searchHostPages('"' . $query . '"', $page * API_SEARCH_PAGINATION_RESULTS_LIMIT - API_SEARCH_PAGINATION_RESULTS_LIMIT, API_SEARCH_PAGINATION_RESULTS_LIMIT, $sphinxResultsTotal); + // Make search request + $sphinxResultsTotal = $sphinx->searchHostPagesTotal('"' . $query . '"'); + $sphinxResults = $sphinx->searchHostPages('"' . $query . '"', $page * API_SEARCH_PAGINATION_RESULTS_LIMIT - API_SEARCH_PAGINATION_RESULTS_LIMIT, API_SEARCH_PAGINATION_RESULTS_LIMIT, $sphinxResultsTotal); - // Generate results - $dbResults = []; + // Generate results + $dbResults = []; - foreach ($sphinxResults as $i => $sphinxResult) { + foreach ($sphinxResults as $i => $sphinxResult) { - if ($hostPage = $db->getFoundHostPage($sphinxResult->id)) { + if ($hostPage = $db->getFoundHostPage($sphinxResult->id)) { - $dbResults[$i] = $hostPage; + $dbResults[$i] = $hostPage; - $dbResults[$i]->weight = $sphinxResult->weight; + $dbResults[$i]->weight = $sphinxResult->weight; + } } - } - // Make response - $response = [ - 'status' => true, - 'totals' => $sphinxResultsTotal, - 'result' => $dbResults, - ]; + // Make response + $response = [ + 'status' => true, + 'totals' => $sphinxResultsTotal, + 'result' => $dbResults, + ]; + + } else { + + $response = [ + 'status' => false, + 'result' => [], + ]; + } break; // Host API case 'hosts'; - // Connect database - $db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); + if (API_HOSTS_ENABLED) { - $response = [ - 'status' => true, - 'totals' => $db->getTotalHosts(), - 'result' => $db->getAPIHosts(API_HOSTS_FIELDS), - ]; + // Connect database + $db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); + + $response = [ + 'status' => true, + 'totals' => $db->getTotalHosts(), + '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; diff --git a/public/index.php b/public/index.php index 578ac6c..252a50c 100644 --- a/public/index.php +++ b/public/index.php @@ -21,6 +21,9 @@ $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the <?php echo _('YGGo! Web Search Engine') ?> + + +