Skip to content

Commit

Permalink
Replace /hashtags endpoint by q filtering on /catalogs endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrom committed Oct 1, 2024
1 parent ad6e97e commit ecf9d10
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 65 deletions.
1 change: 0 additions & 1 deletion app/resto/core/RestoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,6 @@ public function setSummaries($summaries)

$this->summaries = array();

// Datetime is not stored in facet
if ( isset($this->extent['temporal']['interval'][0][0]) && isset($this->extent['temporal']['interval'][0][1]) ) {
$this->summaries['datetime'] = array(
'minimum' => $this->extent['temporal']['interval'][0][0],
Expand Down
2 changes: 1 addition & 1 deletion app/resto/core/RestoModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ abstract class RestoModel
);

/*
* Facet hierarchy
* Auto cataloging hierarchy
*/
public $facetCategories = array(
array(
Expand Down
27 changes: 16 additions & 11 deletions app/resto/core/api/STACAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public function getCatalogs($params)
'description' => 'List of available catalogs',
'links' => array_merge(
$this->getBaseLinks(),
$this->getRootCatalogLinks($this->context->core['catalogMinMatch'])
$this->getRootCatalogLinks($params)
)
);
}
Expand Down Expand Up @@ -674,7 +674,7 @@ public function getChildren($params)
// Initialize router to process each children individually
$router = new RestoRouter($this->context, $this->user);

$links = $this->getRootCatalogLinks($this->context->core['catalogMinMatch']);
$links = $this->getRootCatalogLinks($params);
for ($i = 0, $ii = count($links); $i < $ii; $i++) {
if ($links[$i]['rel'] == 'child') {
try {
Expand Down Expand Up @@ -1306,7 +1306,8 @@ private function processPath($segments, $params = array())

array_pop($segments);
$catalogs = $this->catalogsFunctions->getCatalogs(array(
'id' => join('/', $segments)
'id' => join('/', $segments),
'q' => $params['q'] ?? null
));

if ( empty($catalogs) || !$catalogs[0]['hashtag'] ) {
Expand All @@ -1328,7 +1329,7 @@ private function processPath($segments, $params = array())
}

// The path is the catalog identifier
$parentAndChilds = $this->getParentAndChilds(join('/', $segments));
$parentAndChilds = $this->getParentAndChilds(join('/', $segments), $params);
return array(
'stac_version' => STACAPI::STAC_VERSION,
'id' => $segments[count($segments) -1 ],
Expand Down Expand Up @@ -1453,18 +1454,19 @@ private function jsonQueryToKVP($jsonQuery)
* Return catalog childs
*
* @param string $catalogId
* @param array $params Search parameters
* @return array
*/
private function getParentAndChilds($catalogId)
private function getParentAndChilds($catalogId, $params)
{

// Get catalogs - first one is $catalogId, other its childs
$catalogs = $this->catalogsFunctions->getCatalogs(array(
'id' => $catalogId
'id' => $catalogId,
'q' => $params['q'] ?? null
), true);

$parentAndChilds = array(
'parent' => $catalogs[0],
'parent' => $catalogs[0] ?? null,
'childs' => array()
);

Expand Down Expand Up @@ -1541,9 +1543,10 @@ private function getBaseLinks($segments = array())
/**
* Get root links
*
* @param $params // Additional filtering parameters for catalog search on description and title
* @return array
*/
private function getRootCatalogLinks()
private function getRootCatalogLinks($params)
{
$links = array();

Expand All @@ -1557,10 +1560,11 @@ private function getRootCatalogLinks()
$links[] = $stacLink;
}
}

// Get first level catalog
$catalogs = $this->catalogsFunctions->getCatalogs(array(
'level' => 1
'level' => 1,
'q' => $params['q'] ?? null
));

for ($i = 0, $ii = count($catalogs); $i < $ii; $i++) {
Expand All @@ -1576,6 +1580,7 @@ private function getRootCatalogLinks()
'title' => $catalogs[$i]['title'],
'description' => $catalogs[$i]['description'] ?? '',
'type' => RestoUtil::$contentTypes['json'],
'resto:type' => $catalogs[$i]['rtype'],
'href' => $this->context->core['baseUrl'] . '/catalogs/' . rawurlencode($catalogs[$i]['id']),
'matched' => $catalogs[$i]['counters']['total']
);
Expand Down
11 changes: 6 additions & 5 deletions app/resto/core/dbfunctions/CatalogsFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ public function getCatalogs($params, $withChilds = false)
$where[] = $_where;
}

if ( isset($params['description']) ) {
$values[] = '%' . $params['description'] . '%';
$where[] = 'public.normalize(description) LIKE public.normalize($' . count($values) . ')';
// Filter on description / title
if ( isset($params['q']) ) {
$values[] = '%' . $params['q'] . '%';
$where[] = '(public.normalize(description) ILIKE public.normalize($' . count($values) . ') OR public.normalize(hashtag) ILIKE public.normalize($' . count($values) . ') )';
}

if ( isset($params['level']) ) {
// [IMPORTANT] Discard level if q is set
else if ( isset($params['level']) ) {
$values[] = $params['level'];
$where[] = 'level=$' . count($values);
}
Expand Down
48 changes: 1 addition & 47 deletions resto-database-model/03_resto_target_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -371,46 +371,6 @@ CREATE TABLE IF NOT EXISTS __DATABASE_TARGET_SCHEMA__.feature_optical (

);

--
-- Facets table
--
CREATE TABLE IF NOT EXISTS __DATABASE_TARGET_SCHEMA__.facet (

-- Identifier for the facet (unique in combination with collection id)
id TEXT NOT NULL,

-- Collection id attached to the facet
collection TEXT NOT NULL,

-- Facet value
value TEXT,

-- Facet type (i.e. catalog, hashtag, region, state, location, etc.)
type TEXT,

-- Parent identifier (i.e. 'europe' for facet 'france')
pid TEXT NOT NULL,

-- Set to 1 if facet is a terminal leaf, 0 otherwise (used for STAC)
isleaf INTEGER,

-- Number of appearance of this facet within the collection
counter INTEGER,

-- Facet date of creation
created TIMESTAMP DEFAULT now(),

-- Owner of the facet i.e. first user to create it
owner BIGINT,

-- Description
description TEXT,

-- The id, pid, collection pair should be unique
PRIMARY KEY (id, pid, collection)

);

--
-- Catalog table
--
Expand Down Expand Up @@ -491,16 +451,10 @@ ALTER TABLE ONLY __DATABASE_TARGET_SCHEMA__.osdescription ADD CONSTRAINT cl_coll
CREATE INDEX IF NOT EXISTS idx_collection_osdescription ON __DATABASE_TARGET_SCHEMA__.osdescription (collection);
-- CREATE INDEX IF NOT EXISTS idx_lang_osdescription ON __DATABASE_TARGET_SCHEMA__.osdescription (lang);

-- [TABLE __DATABASE_TARGET_SCHEMA__.facet]
CREATE INDEX IF NOT EXISTS idx_id_facet ON __DATABASE_TARGET_SCHEMA__.facet (public.normalize(id));
CREATE INDEX IF NOT EXISTS idx_pid_facet ON __DATABASE_TARGET_SCHEMA__.facet (public.normalize(pid));
CREATE INDEX IF NOT EXISTS idx_type_facet ON __DATABASE_TARGET_SCHEMA__.facet (type);
CREATE INDEX IF NOT EXISTS idx_collection_facet ON __DATABASE_TARGET_SCHEMA__.facet (public.normalize(collection));
CREATE INDEX IF NOT EXISTS idx_value_facet ON __DATABASE_TARGET_SCHEMA__.facet USING GIN (public.normalize(value) gin_trgm_ops);

-- [TABLE __DATABASE_TARGET_SCHEMA__.catalog]
CREATE INDEX IF NOT EXISTS idx_id_catalog ON __DATABASE_TARGET_SCHEMA__.catalog (public.normalize(id));
CREATE INDEX IF NOT EXISTS idx_description_catalog ON __DATABASE_TARGET_SCHEMA__.catalog USING GIN (public.normalize(description) gin_trgm_ops);
CREATE INDEX IF NOT EXISTS idx_hashtag_catalog ON __DATABASE_TARGET_SCHEMA__.catalog USING GIN (public.normalize(hashtag) gin_trgm_ops);
CREATE INDEX IF NOT EXISTS idx_level_catalog ON __DATABASE_TARGET_SCHEMA__.catalog USING btree (level);

-- [TABLE __DATABASE_TARGET_SCHEMA__.hashtag]
Expand Down

0 comments on commit ecf9d10

Please sign in to comment.