|
|
@ -69,7 +69,7 @@ $placeholder = plural( |
|
|
|
$response = false; |
|
|
|
$response = false; |
|
|
|
|
|
|
|
|
|
|
|
// Request |
|
|
|
// Request |
|
|
|
$q = !empty($_GET['q']) ? $_GET['q'] : ''; |
|
|
|
$q = !empty($_GET['q']) ? trim($_GET['q']) : ''; |
|
|
|
$p = !empty($_GET['p']) ? (int) $_GET['p'] : 1; |
|
|
|
$p = !empty($_GET['p']) ? (int) $_GET['p'] : 1; |
|
|
|
|
|
|
|
|
|
|
|
// Register new URL by request on enabled |
|
|
|
// Register new URL by request on enabled |
|
|
@ -77,10 +77,13 @@ if ($config->webui->search->index->request->url->enabled) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (filter_var($q, FILTER_VALIDATE_URL) && preg_match($config->webui->search->index->request->url->regex, $q)) |
|
|
|
if (filter_var($q, FILTER_VALIDATE_URL) && preg_match($config->webui->search->index->request->url->regex, $q)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$url = trim($q); |
|
|
|
// Prepare URL |
|
|
|
|
|
|
|
$url = $q; |
|
|
|
|
|
|
|
$crc32url = crc32($url); |
|
|
|
|
|
|
|
|
|
|
|
// Check URL for exist |
|
|
|
// Check URL for exist |
|
|
|
$exist = $index->search('@url "' . trim($url) . '"') |
|
|
|
$exist = $index->search('@url "' . $url . '"') |
|
|
|
|
|
|
|
->filter('crc32url', $crc32url) |
|
|
|
->limit(1) |
|
|
|
->limit(1) |
|
|
|
->get() |
|
|
|
->get() |
|
|
|
->getTotal(); |
|
|
|
->getTotal(); |
|
|
@ -90,7 +93,7 @@ if ($config->webui->search->index->request->url->enabled) |
|
|
|
/* disable as regular search request possible |
|
|
|
/* disable as regular search request possible |
|
|
|
$response = sprintf( |
|
|
|
$response = sprintf( |
|
|
|
_('URL "%s" exists in search index'), |
|
|
|
_('URL "%s" exists in search index'), |
|
|
|
htmlentities($url) |
|
|
|
htmlentities($q) |
|
|
|
); |
|
|
|
); |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
} |
|
|
|
} |
|
|
@ -98,36 +101,39 @@ if ($config->webui->search->index->request->url->enabled) |
|
|
|
// Add URL |
|
|
|
// Add URL |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
// @TODO check http code |
|
|
|
|
|
|
|
|
|
|
|
$index->addDocument( |
|
|
|
$index->addDocument( |
|
|
|
[ |
|
|
|
[ |
|
|
|
'url' => trim($url) |
|
|
|
'url' => $url, |
|
|
|
|
|
|
|
'crc32url' => $crc32url |
|
|
|
] |
|
|
|
] |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$response = sprintf( |
|
|
|
$response = sprintf( |
|
|
|
_('URL "%s" added to the crawl queue!'), |
|
|
|
_('URL "%s" added to the crawl queue!'), |
|
|
|
htmlentities($url) |
|
|
|
htmlentities($q) |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Extended syntax corrections |
|
|
|
// Extended syntax corrections |
|
|
|
$query = trim($q); |
|
|
|
switch (true) |
|
|
|
|
|
|
|
|
|
|
|
if (filter_var($q, FILTER_VALIDATE_URL)) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
$query = '@url "' . $q . '"'; |
|
|
|
case filter_var($q, FILTER_VALIDATE_URL): |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elseif (false === strpos($q, '"')) |
|
|
|
$query = $index->search('@url "' . $q . '"')->filter('crc32url', crc32($q)); |
|
|
|
{ |
|
|
|
|
|
|
|
$query = '"' . $q . '"'; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$query = $index->search($q); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Search request begin |
|
|
|
// Search request begin |
|
|
|
$results = $index->search($query) |
|
|
|
$results = $query->offset($p * $config->webui->pagination->limit - $config->webui->pagination->limit) |
|
|
|
->offset($p * $config->webui->pagination->limit - $config->webui->pagination->limit) |
|
|
|
|
|
|
|
->limit($config->webui->pagination->limit) |
|
|
|
->limit($config->webui->pagination->limit) |
|
|
|
->get(); |
|
|
|
->get(); |
|
|
|
|
|
|
|
|
|
|
|