@@ -258,6 +258,22 @@ public function __construct($context, $user)
258
258
* summary="Get STAC catalogs",
259
259
* description="Get STAC catalogs",
260
260
* 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
+ * ),
261
277
* @OA\Response(
262
278
* response="200",
263
279
* description="STAC catalog definition - contains links to child catalogs and/or items",
@@ -1313,7 +1329,8 @@ private function processPath($segments, $params = array())
1313
1329
array_pop ($ segments );
1314
1330
$ catalogs = $ this ->catalogsFunctions ->getCatalogs (array (
1315
1331
'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
1317
1334
), $ this ->context ->core ['baseUrl ' ], false );
1318
1335
1319
1336
if ( empty ($ catalogs ) ) {
@@ -1474,7 +1491,8 @@ private function getParentAndChilds($catalogId, $params)
1474
1491
// Get catalogs - first one is $catalogId, other its childs
1475
1492
$ catalogs = $ this ->catalogsFunctions ->getCatalogs (array (
1476
1493
'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
1478
1496
), $ this ->context ->core ['baseUrl ' ], true );
1479
1497
1480
1498
if ( empty ($ catalogs ) ) {
@@ -1497,9 +1515,11 @@ private function getParentAndChilds($catalogId, $params)
1497
1515
$ element = array (
1498
1516
'rel ' => 'items ' ,
1499
1517
'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 ' ]))) . '/_ '
1502
1519
);
1520
+ if ( $ parentAndChilds ['parent ' ]['counters ' ]['total ' ] > 0 ) {
1521
+ $ element ['matched ' ] = $ parentAndChilds ['parent ' ]['counters ' ]['total ' ];
1522
+ }
1503
1523
if ( isset ($ parentAndChilds ['parent ' ]['title ' ]) ) {
1504
1524
$ element ['title ' ] = $ parentAndChilds ['parent ' ]['title ' ];
1505
1525
}
@@ -1510,11 +1530,14 @@ private function getParentAndChilds($catalogId, $params)
1510
1530
for ($ i = 1 , $ ii = count ($ catalogs ); $ i < $ ii ; $ i ++) {
1511
1531
if ($ catalogs [$ i ]['level ' ] === $ parentAndChilds ['parent ' ]['level ' ] + 1 ) {
1512
1532
$ element = array (
1533
+ 'id ' => $ catalogs [$ i ]['id ' ],
1513
1534
'rel ' => 'child ' ,
1514
1535
'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 ' ])))
1517
1537
);
1538
+ if ( $ catalogs [$ i ]['counters ' ]['total ' ] > 0 ) {
1539
+ $ element ['matched ' ] = $ catalogs [$ i ]['counters ' ]['total ' ];
1540
+ }
1518
1541
if ( isset ($ catalogs [$ i ]['title ' ]) ) {
1519
1542
$ element ['title ' ] = $ catalogs [$ i ]['title ' ];
1520
1543
}
@@ -1587,50 +1610,55 @@ private function getRootCatalogLinks($params)
1587
1610
$ links [] = $ stacLink ;
1588
1611
}
1589
1612
}
1590
-
1613
+
1591
1614
// Get first level catalog
1592
1615
$ catalogs = $ this ->catalogsFunctions ->getCatalogs (array (
1593
1616
'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
1595
1619
), $ 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
+ }
1605
1632
}
1606
1633
}
1607
1634
}
1608
- for ( $ i = 0 , $ ii = count ( $ catalogs ); $ i < $ ii ; $ i ++) {
1635
+ */
1609
1636
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 ++) {
1612
1638
1613
- if ($ catalogs [$ i ]['id ' ] === 'collections ' ) {
1614
- continue ;
1615
- }
1639
+ if ($ catalogs [$ i ]['id ' ] === 'collections ' ) {
1640
+ continue ;
1641
+ }
1616
1642
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 ' ];
1633
1660
}
1661
+ $ links [] = $ link ;
1634
1662
1635
1663
}
1636
1664
0 commit comments