Skip to content

Commit f77457d

Browse files
authored
Merge pull request #458 from jjrom/develop
Return catalog id in links
2 parents 12d308b + 38b2918 commit f77457d

File tree

8 files changed

+81
-54
lines changed

8 files changed

+81
-54
lines changed

app/resto/core/RestoCollections.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,22 +292,28 @@ public function toArray()
292292
continue;
293293
}
294294

295-
$collections['links'][] = array(
295+
$link = array(
296296
'rel' => 'child',
297297
'type' => RestoUtil::$contentTypes['json'],
298298
'title' => $collection['title'],
299299
'description' => $collection['description'],
300-
'matched' => $matched,
301300
'href' => $this->context->core['baseUrl'] . RestoUtil::replaceInTemplate(RestoRouter::ROUTE_TO_COLLECTION, array('collectionId' => $key)),
302301
'roles' => array('collection')
303302
);
303+
if ( $matche > 0 ) {
304+
$link['matched'] = $matched;
305+
}
306+
$collections['links'][] = $link;
307+
304308
$collections['collections'][] = $collection;
305309
$totalMatched += $collection['summaries']['collection']['count'] ?? 0;
306310
}
307311

308312
// Update count for all collections
309-
$collections['links'][2]['matched'] = $totalMatched;
310-
313+
if ( $totalMatched > 0 ) {
314+
$collections['links'][2]['matched'] = $totalMatched;
315+
}
316+
311317
/*
312318
* Sort collections array alphabetically (based on collection title)
313319
*/

app/resto/core/RestoConstants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RestoConstants
2020
// [IMPORTANT] Starting resto 7.x, default routes are defined in RestoRouter class
2121

2222
// resto version
23-
const VERSION = '9.0.0-RC21';
23+
const VERSION = '9.0.0-RC22';
2424

2525
/* ============================================================
2626
* NEVER EVER TOUCH THESE VALUES

app/resto/core/RestoContext.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ class RestoContext
5050
// True to store all user queries to database
5151
'storeQuery' => false,
5252

53-
// Display catalog that have at least 'catalogMinMatch' object
54-
'catalogMinMatch' => 0,
55-
5653
// Display collection that have at least 'collectionMinMatch' object
5754
'collectionMinMatch' => 0,
5855

app/resto/core/api/STACAPI.php

Lines changed: 67 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,22 @@ public function __construct($context, $user)
258258
* summary="Get STAC catalogs",
259259
* description="Get STAC catalogs",
260260
* tags={"STAC"},
261+
* @OA\Parameter(
262+
* name="q",
263+
* in="query",
264+
* description="Filter on catalog id and description",
265+
* @OA\Schema(
266+
* type="string"
267+
* )
268+
* ),
269+
* @OA\Parameter(
270+
* name="_nocount",
271+
* in="query",
272+
* description="Set to 1 to not count number of items below catalogs. Speed up *a lot* the query so should be used when using this for suggest (see rocket catalog search for instance)",
273+
* @OA\Schema(
274+
* type="boolean"
275+
* )
276+
* ),
261277
* @OA\Response(
262278
* response="200",
263279
* description="STAC catalog definition - contains links to child catalogs and/or items",
@@ -1313,7 +1329,8 @@ private function processPath($segments, $params = array())
13131329
array_pop($segments);
13141330
$catalogs = $this->catalogsFunctions->getCatalogs(array(
13151331
'id' => join('/', $segments),
1316-
'q' => $params['q'] ?? null
1332+
'q' => $params['q'] ?? null,
1333+
'noCount' => isset($params['_nocount']) ? filter_var($params['_nocount'], FILTER_VALIDATE_BOOLEAN) : false
13171334
), $this->context->core['baseUrl'], false);
13181335

13191336
if ( empty($catalogs) ) {
@@ -1474,7 +1491,8 @@ private function getParentAndChilds($catalogId, $params)
14741491
// Get catalogs - first one is $catalogId, other its childs
14751492
$catalogs = $this->catalogsFunctions->getCatalogs(array(
14761493
'id' => $catalogId,
1477-
'q' => $params['q'] ?? null
1494+
'q' => $params['q'] ?? null,
1495+
'noCount' => isset($params['_nocount']) ? filter_var($params['_nocount'], FILTER_VALIDATE_BOOLEAN) : false
14781496
), $this->context->core['baseUrl'], true);
14791497

14801498
if ( empty($catalogs) ) {
@@ -1497,9 +1515,11 @@ private function getParentAndChilds($catalogId, $params)
14971515
$element = array(
14981516
'rel' => 'items',
14991517
'type' => RestoUtil::$contentTypes['geojson'],
1500-
'href' => $this->context->core['baseUrl'] . '/catalogs/' . join('/', array_map('rawurlencode', explode('/', $parentAndChilds['parent']['id']))) . '/_',
1501-
'matched' => $parentAndChilds['parent']['counters']['total']
1518+
'href' => $this->context->core['baseUrl'] . '/catalogs/' . join('/', array_map('rawurlencode', explode('/', $parentAndChilds['parent']['id']))) . '/_'
15021519
);
1520+
if ( $parentAndChilds['parent']['counters']['total'] > 0 ) {
1521+
$element['matched'] = $parentAndChilds['parent']['counters']['total'];
1522+
}
15031523
if ( isset($parentAndChilds['parent']['title']) ) {
15041524
$element['title'] = $parentAndChilds['parent']['title'];
15051525
}
@@ -1510,11 +1530,14 @@ private function getParentAndChilds($catalogId, $params)
15101530
for ($i = 1, $ii = count($catalogs); $i < $ii; $i++) {
15111531
if ($catalogs[$i]['level'] === $parentAndChilds['parent']['level'] + 1) {
15121532
$element = array(
1533+
'id' => $catalogs[$i]['id'],
15131534
'rel' => 'child',
15141535
'type' => RestoUtil::$contentTypes['json'],
1515-
'href' => $this->context->core['baseUrl'] . '/catalogs/' . join('/', array_map('rawurlencode', explode('/', $catalogs[$i]['id']))),
1516-
'matched' => $catalogs[$i]['counters']['total']
1536+
'href' => $this->context->core['baseUrl'] . '/catalogs/' . join('/', array_map('rawurlencode', explode('/', $catalogs[$i]['id'])))
15171537
);
1538+
if ( $catalogs[$i]['counters']['total'] > 0 ) {
1539+
$element['matched'] = $catalogs[$i]['counters']['total'];
1540+
}
15181541
if ( isset($catalogs[$i]['title']) ) {
15191542
$element['title'] = $catalogs[$i]['title'];
15201543
}
@@ -1587,50 +1610,55 @@ private function getRootCatalogLinks($params)
15871610
$links[] = $stacLink;
15881611
}
15891612
}
1590-
1613+
15911614
// Get first level catalog
15921615
$catalogs = $this->catalogsFunctions->getCatalogs(array(
15931616
'level' => 1,
1594-
'q' => $params['q'] ?? null
1617+
'q' => $params['q'] ?? null,
1618+
'noCount' => isset($params['_nocount']) ? filter_var($params['_nocount'], FILTER_VALIDATE_BOOLEAN) : false
15951619
), $this->context->core['baseUrl'], false);
1596-
1597-
// Then compute subcatalogs for counts
1598-
for ($i = 0, $ii = count($catalogs); $i < $ii; $i++) {
1599-
$subCatalogs = $this->catalogsFunctions->getCatalogs(array(
1600-
'id' => $catalogs[$i]['id']
1601-
), $this->context->core['baseUrl'], true);
1602-
for ($j = 0, $jj = count($subCatalogs); $j < $jj; $j++) {
1603-
if ($subCatalogs[$j]['id'] === $catalogs[$i]['id']) {
1604-
$catalogs[$i] = $subCatalogs[$j];
1620+
1621+
/*
1622+
* [TODO] Remove to slow - Then compute subcatalogs for counts
1623+
if (filter_var($params['_nocount'] ?? false, FILTER_VALIDATE_BOOLEAN) === false) {
1624+
for ($i = 0, $ii = count($catalogs); $i < $ii; $i++) {
1625+
$subCatalogs = $this->catalogsFunctions->getCatalogs(array(
1626+
'id' => $catalogs[$i]['id']
1627+
), $this->context->core['baseUrl'], true);
1628+
for ($j = 0, $jj = count($subCatalogs); $j < $jj; $j++) {
1629+
if ($subCatalogs[$j]['id'] === $catalogs[$i]['id']) {
1630+
$catalogs[$i] = $subCatalogs[$j];
1631+
}
16051632
}
16061633
}
16071634
}
1608-
for ($i = 0, $ii = count($catalogs); $i < $ii; $i++) {
1635+
*/
16091636

1610-
// Returns only catalogs with count >= minMatch
1611-
if ($catalogs[$i]['counters']['total'] >= $this->context->core['catalogMinMatch']) {
1637+
for ($i = 0, $ii = count($catalogs); $i < $ii; $i++) {
16121638

1613-
if ($catalogs[$i]['id'] === 'collections') {
1614-
continue;
1615-
}
1639+
if ($catalogs[$i]['id'] === 'collections') {
1640+
continue;
1641+
}
16161642

1617-
$link = array(
1618-
'rel' => 'child',
1619-
'type' => RestoUtil::$contentTypes['json'],
1620-
'href' => $this->context->core['baseUrl'] . '/catalogs/' . rawurlencode($catalogs[$i]['id']),
1621-
'matched' => $catalogs[$i]['counters']['total'] ?? 0
1622-
);
1623-
if ( isset($catalogs[$i]['title']) ) {
1624-
$link['title'] = $catalogs[$i]['title'];
1625-
}
1626-
if ( isset($catalogs[$i]['description']) ) {
1627-
$link['description'] = $catalogs[$i]['description'];
1628-
}
1629-
if ( isset($catalogs[$i]['rtype']) ) {
1630-
$link['resto:type'] = $catalogs[$i]['rtype'];
1631-
}
1632-
$links[] = $link;
1643+
$link = array(
1644+
'id' => $catalogs[$i]['id'],
1645+
'rel' => 'child',
1646+
'type' => RestoUtil::$contentTypes['json'],
1647+
'href' => $this->context->core['baseUrl'] . '/catalogs/' . rawurlencode($catalogs[$i]['id'])
1648+
);
1649+
if ( $catalogs[$i]['counters']['total'] > 0 ) {
1650+
$link['matched'] = $catalogs[$i]['counters']['total'];
1651+
}
1652+
if ( isset($catalogs[$i]['title']) ) {
1653+
$link['title'] = $catalogs[$i]['title'];
1654+
}
1655+
if ( isset($catalogs[$i]['description']) ) {
1656+
$link['description'] = $catalogs[$i]['description'];
1657+
}
1658+
if ( isset($catalogs[$i]['rtype']) ) {
1659+
$link['resto:type'] = $catalogs[$i]['rtype'];
16331660
}
1661+
$links[] = $link;
16341662

16351663
}
16361664

app/resto/core/dbfunctions/CatalogsFunctions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function getCatalogs($params, $baseUrl, $withChilds)
151151
/*
152152
* Recursively add child collection counters to catalog counters
153153
*/
154-
return $this->onTheFlyUpdateCountersWithCollection($catalogs, $baseUrl);
154+
return !empty($params['noCount']) ? $catalogs : $this->onTheFlyUpdateCountersWithCollection($catalogs, $baseUrl);
155155

156156
}
157157

app/resto/core/dbfunctions/FiltersFunctions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,12 +895,12 @@ private function optimizeNotEqual($operation, $before, $after)
895895
}
896896

897897
/**
898-
* Remove invalid character from $searchTerm
898+
* Replace invalid character from $searchTerm
899899
*
900900
* @param string $searchTerm
901901
*/
902902
private function cleanSearchTerm($searchTerm)
903903
{
904-
return str_replace(array('#', '%'), '', $searchTerm);
904+
return str_replace(array('#', '%'), '_', $searchTerm);
905905
}
906906
}

build/resto/config.php.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ return array(
1111
'endpoint' => '${STORAGE_PUBLIC_ENDPOINT:-/static}'
1212
),
1313
'storeQuery' => ${STORE_QUERY:-false},
14-
'catalogMinMatch' => ${CATALOG_MINMATCH:-0},
1514
'collectionMinMatch' => ${COLLECTION_MINMATCH:-0},
1615
'timezone' => '${TIMEZONE:-Europe/Paris}',
1716
'tokenDuration' => ${JWT_DURATION:-8640000},

config.env

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ JWT_PASSPHRASE="Super secret passphrase"
9696
### True to store all user queries to database
9797
#STORE_QUERY=false
9898

99-
### STAC - only display child/items links with at least minMatch child/items
100-
#CATALOG_MINMATCH=0
101-
10299
### OGC API FEATURES - only display collection links with at least minMatch child/items
103100
#COLLECTION_MINMATCH=0
104101

0 commit comments

Comments
 (0)