mirror of
https://github.com/YGGverse/YGGo.git
synced 2025-01-08 22:07:56 +00:00
implement extended search mode support #9
This commit is contained in:
parent
fb5cfe4f50
commit
0bd765064b
15
README.md
15
README.md
@ -63,6 +63,7 @@ Could be enabled or disabled by `API_SEARCH_ENABLED` option
|
|||||||
GET action=search - required
|
GET action=search - required
|
||||||
GET query={string} - optional, search request, empty if not provided
|
GET query={string} - optional, search request, empty if not provided
|
||||||
GET page={int} - optional, search results page, 1 if not provided
|
GET page={int} - optional, search results page, 1 if not provided
|
||||||
|
GET mode=SphinxQL - optional, enable extended SphinxQL syntax
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Hosts distribution
|
##### Hosts distribution
|
||||||
@ -91,9 +92,7 @@ GET action=manifest - required
|
|||||||
|
|
||||||
#### Search textual filtering
|
#### Search textual filtering
|
||||||
|
|
||||||
https://sphinxsearch.com/docs/current.html#extended-syntax
|
##### Default constructions
|
||||||
|
|
||||||
##### Supported constructions
|
|
||||||
|
|
||||||
```
|
```
|
||||||
operator OR:
|
operator OR:
|
||||||
@ -126,6 +125,16 @@ boosted^1.234 boostedfieldend$^1.234
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### Extended syntax
|
||||||
|
|
||||||
|
https://sphinxsearch.com/docs/current.html#extended-syntax
|
||||||
|
|
||||||
|
Could be enabled with following attributes
|
||||||
|
|
||||||
|
```
|
||||||
|
GET m=SphinxQL
|
||||||
|
```
|
||||||
|
|
||||||
#### Roadmap / ideas
|
#### Roadmap / ideas
|
||||||
|
|
||||||
* [x] Web pages full text ranking search
|
* [x] Web pages full text ranking search
|
||||||
|
@ -55,9 +55,11 @@ class Filter {
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function sphinxSearchQuery(string $query) {
|
static public function searchQuery(string $query, string $mode = 'default') {
|
||||||
|
|
||||||
|
if ($mode == 'default') {
|
||||||
$query = str_replace(['\\', '/', '~', '@', '!', '"', '(', ')'], ['\\\\', '\/', '\~', '\@', '\!', '\"', '\(', '\)'], $query);
|
$query = str_replace(['\\', '/', '~', '@', '!', '"', '(', ')'], ['\\\\', '\/', '\~', '\@', '\!', '\"', '\(', '\)'], $query);
|
||||||
|
}
|
||||||
|
|
||||||
$query = trim($query);
|
$query = trim($query);
|
||||||
|
|
||||||
|
@ -30,12 +30,13 @@ if (API_ENABLED) {
|
|||||||
|
|
||||||
|
|
||||||
// Filter request data
|
// Filter request data
|
||||||
|
$mode = !empty($_GET['mode']) ? Filter::url($_GET['mode']) : 'default';
|
||||||
$query = !empty($_GET['query']) ? Filter::url($_GET['query']) : '';
|
$query = !empty($_GET['query']) ? Filter::url($_GET['query']) : '';
|
||||||
$page = !empty($_GET['page']) ? Filter::url($_GET['page']) : 1;
|
$page = !empty($_GET['page']) ? (int) $_GET['page'] : 1;
|
||||||
|
|
||||||
// Make search request
|
// Make search request
|
||||||
$sphinxResultsTotal = $sphinx->searchHostPagesTotal(Filter::sphinxSearchQuery($query));
|
$sphinxResultsTotal = $sphinx->searchHostPagesTotal(Filter::searchQuery($query, $mode));
|
||||||
$sphinxResults = $sphinx->searchHostPages(Filter::sphinxSearchQuery($query), $page * API_SEARCH_PAGINATION_RESULTS_LIMIT - API_SEARCH_PAGINATION_RESULTS_LIMIT, API_SEARCH_PAGINATION_RESULTS_LIMIT, $sphinxResultsTotal);
|
$sphinxResults = $sphinx->searchHostPages(Filter::searchQuery($query, $mode), $page * API_SEARCH_PAGINATION_RESULTS_LIMIT - API_SEARCH_PAGINATION_RESULTS_LIMIT, API_SEARCH_PAGINATION_RESULTS_LIMIT, $sphinxResultsTotal);
|
||||||
|
|
||||||
// Generate results
|
// Generate results
|
||||||
$dbResults = [];
|
$dbResults = [];
|
||||||
|
@ -24,6 +24,7 @@ $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// Filter request data
|
// Filter request data
|
||||||
|
$m = !empty($_GET['m']) ? Filter::url($_GET['m']) : 'default';
|
||||||
$q = !empty($_GET['q']) ? Filter::url($_GET['q']) : '';
|
$q = !empty($_GET['q']) ? Filter::url($_GET['q']) : '';
|
||||||
$p = !empty($_GET['p']) ? (int) $_GET['p'] : 1;
|
$p = !empty($_GET['p']) ? (int) $_GET['p'] : 1;
|
||||||
|
|
||||||
@ -106,8 +107,8 @@ if (filter_var($q, FILTER_VALIDATE_URL) && preg_match(CRAWL_URL_REGEXP, $q)) {
|
|||||||
// Search request
|
// Search request
|
||||||
if (!empty($q)) {
|
if (!empty($q)) {
|
||||||
|
|
||||||
$resultsTotal = $sphinx->searchHostPagesTotal(Filter::sphinxSearchQuery($q));
|
$resultsTotal = $sphinx->searchHostPagesTotal(Filter::searchQuery($q, $m));
|
||||||
$results = $sphinx->searchHostPages(Filter::sphinxSearchQuery($q), $p * WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT - WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT, WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT, $resultsTotal);
|
$results = $sphinx->searchHostPages(Filter::searchQuery($q, $m), $p * WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT - WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT, WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT, $resultsTotal);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user