Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct duplicate where clause #444

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/resto/core/RestoConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RestoConstants
// [IMPORTANT] Starting resto 7.x, default routes are defined in RestoRouter class

// resto version
const VERSION = '9.0.0-RC9';
const VERSION = '9.0.0-RC10';

/* ============================================================
* NEVER EVER TOUCH THESE VALUES
Expand Down
3 changes: 1 addition & 2 deletions app/resto/core/dbfunctions/CatalogsFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,7 @@ private function getCleanLinks($catalog, $userid, $baseUrl) {
}

/*
* [TODO] Local collection -should not be in links but should appears in catalog
* under /catalogs/catalogThatIsIngested/{collectionId} so we can keep trace of this in item ??
* Store local collection within links
*/
if ( $link['rel'] === 'child' && str_starts_with($link['href'], $baseUrl . RestoRouter::ROUTE_TO_COLLECTIONS )) {
$output['links'][] = $link;
Expand Down
34 changes: 23 additions & 11 deletions app/resto/core/dbfunctions/FiltersFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,29 @@ public function prepareFilters($paramsWithOperation, $sortKey)
}

$catalogFeatureTableName = $this->context->dbDriver->targetSchema . '.catalog_feature';
if (count($flatTerms) == 1) {

$this->joins[] = 'JOIN ' . $catalogFeatureTableName . ' ON ' . $this->context->dbDriver->targetSchema . '.feature.id=' . $catalogFeatureTableName . '.featureId';
$filters[] = array(
'value' => join(' AND ', array_merge($flatTerms)),
'isGeo' => false
);

}

// Nightmarish one - use WITH and having count

/*
* Query to check for the existence of multiple specific paths.
* This is achieved using a combination of JOIN operations or GROUP BY to count the matching paths for each featureid.
*
* Using HAVING and GROUP BY : the idea is to group by featureid and ensure that the count of matched paths for each
* featureid equals the number of paths you are searching for.
*
* Example to search for 'years.2023' and 'platforms.s2a'
*
* SELECT featureid
* FROM resto.catalog_feature
* WHERE path IN (text2ltree('years.2023'), text2ltree('platforms.s2a'))
* GROUP BY featureid
* HAVING COUNT(DISTINCT path) = 2; -- Replace 2 with the number of paths you're checking
*
* Explanation :
*
* WHERE path IN (...): checks if the path is one of the specified paths.
* GROUP BY featureid: groups the results by featureid, so we can count how many paths match for each featureid
* HAVING COUNT(DISTINCT path) = X: ensures that the number of distinct paths for each featureid matches the number
* of paths we're looking for. Replace X with the number of paths we're querying for (e.g., 2 in the example).
*/
$this->joins[] = 'JOIN matched_paths mp ON ' . $this->context->dbDriver->targetSchema . '.feature.id=mp.featureId';
$this->withs[] = 'WITH matched_paths AS ( SELECT featureid FROM ' . $catalogFeatureTableName . ' WHERE ' . join(' OR ', array_merge($flatTerms)) . ' GROUP BY featureid HAVING COUNT(DISTINCT ' . $catalogFeatureTableName . '.path) >= ' . count($flatTerms) . ')';

Expand Down
5 changes: 4 additions & 1 deletion resto-database-model/03_resto_target_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,10 @@ CREATE TABLE IF NOT EXISTS __DATABASE_TARGET_SCHEMA__.catalog (
visibility INTEGER,

-- resto type
rtype TEXT
rtype TEXT,

-- Free object to store info
properties JSON

);

Expand Down
Loading