From e0b0bc5dc88125d50186b9c0bb032bb57d14804b Mon Sep 17 00:00:00 2001 From: psdigital Date: Tue, 8 Sep 2020 09:13:14 +1200 Subject: [PATCH 1/4] Add table name to join query --- src/SearchPageController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/SearchPageController.php b/src/SearchPageController.php index 71afb00..e1ac8b9 100755 --- a/src/SearchPageController.php +++ b/src/SearchPageController.php @@ -427,6 +427,7 @@ public function PerformSearch(){ $filter_join = $filter['JoinTables'][$type['Key']]; $joins.= "LEFT JOIN \"".$filter_join['Table']."\" ON \"".$type['Table']."\".\"ID\" = \"".$filter_join['Column']."\""; + $joins.= "LEFT JOIN \"".$filter_join['Table']."\" ON \"".$type['Table']."\".\"ID\" = \"".$filter_join['Table']."\".\"".$filter_join['Column']."\""; if (is_array($filter['Value'])){ $ids = ''; @@ -440,6 +441,9 @@ public function PerformSearch(){ $ids = $filter['Value']; } + if ($relations_sql !== ''){ + $relations_sql.= " AND "; + } $relations_sql.= "\"".$filter_join['Table']."\".\"".$filter['Table']."ID\" IN (". $ids .")"; } From 96f134abd447a75083a52e11111b207a87b80fc4 Mon Sep 17 00:00:00 2001 From: psdigital Date: Tue, 8 Sep 2020 09:19:32 +1200 Subject: [PATCH 2/4] Update naming of package --- composer.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 4cf5edc..09e3cd7 100755 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { - "name": "jaedb/search", + "name": "plasticstudio/search", "type": "silverstripe-vendormodule", "description": "SilverStripe search engine", - "homepage": "http://jamesbarnsley.co.nz", + "homepage": "https://psdigital.co.nz", "keywords": ["silverstripe"], "license": "BSD-3-Clause", "authors": [ @@ -13,7 +13,7 @@ } ], "support": { - "issues": "http://github.com/jaedb/search/issues" + "issues": "http://github.com/plasticstudio/search/issues" }, "extra": { "expose": [ diff --git a/package.json b/package.json index a3647d9..231671f 100755 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.1.0", "author": "James Barnsley", "description": "SilverStripe Search Engine", - "repository": "https://github.com/jaedb/search", + "repository": "https://github.com/plasticstudio/search", "licenses": { "type": "Apache License", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" From 9b560f8f63d2857ccbced7abcd489ffd1c33fdef Mon Sep 17 00:00:00 2001 From: psdigital Date: Tue, 8 Sep 2020 09:35:55 +1200 Subject: [PATCH 3/4] Update namespacing to plasticstudio --- README.md | 2 +- _config/config.yml | 4 ++-- src/SearchControllerExtension.php | 2 +- src/SearchPage.php | 2 +- src/SearchPageController.php | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e506df9..c17adf1 100755 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Name: search Before: - '#site' --- -Jaedb\Search\SearchPageController: +PlasticStudio\Search\SearchPageController: types: docs: Label: 'Documents' diff --git a/_config/config.yml b/_config/config.yml index e3ed9d8..32fd984 100755 --- a/_config/config.yml +++ b/_config/config.yml @@ -5,8 +5,8 @@ Before: --- SilverStripe\Control\Controller: extensions: - - Jaedb\Search\SearchControllerExtension -Jaedb\Search\SearchPageController: + - PlasticStudio\Search\SearchControllerExtension +PlasticStudio\Search\SearchPageController: # types: # docs: # Label: 'Documents' diff --git a/src/SearchControllerExtension.php b/src/SearchControllerExtension.php index 31c5f3f..4e87711 100755 --- a/src/SearchControllerExtension.php +++ b/src/SearchControllerExtension.php @@ -1,6 +1,6 @@ get('Jaedb\Search\SearchPageController', 'types'); + $types = Config::inst()->get('PlasticStudio\Search\SearchPageController', 'types'); $array = []; if ($types){ @@ -73,7 +73,7 @@ public static function get_types_available(){ } public static function get_filters_available(){ - $filters = Config::inst()->get('Jaedb\Search\SearchPageController', 'filters'); + $filters = Config::inst()->get('PlasticStudio\Search\SearchPageController', 'filters'); $array = []; if ($filters){ @@ -87,7 +87,7 @@ public static function get_filters_available(){ } public static function get_sorts_available(){ - $sorts = Config::inst()->get('Jaedb\Search\SearchPageController', 'sorts'); + $sorts = Config::inst()->get('PlasticStudio\Search\SearchPageController', 'sorts'); $array = []; if ($sorts){ From 6cc25ad14d29878838a3aa0918e0796a21bd449d Mon Sep 17 00:00:00 2001 From: psdigital Date: Tue, 8 Sep 2020 10:44:35 +1200 Subject: [PATCH 4/4] Repair sort issue, remove duplicates --- src/SearchPageController.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/SearchPageController.php b/src/SearchPageController.php index 2f8b008..f3c30d0 100755 --- a/src/SearchPageController.php +++ b/src/SearchPageController.php @@ -22,11 +22,11 @@ class SearchPageController extends PageController { public function index($request){ if (Director::isLive()){ - Requirements::css('/resources/jaedb/search/client/Search.min.css'); - Requirements::javascript('/resources/jaedb/search/client/Search.min.js'); + Requirements::css('/resources/plasticstudio/search/client/Search.min.css'); + Requirements::javascript('/resources/plasticstudio/search/client/Search.min.js'); } else { - Requirements::css('/resources/jaedb/search/client/Search.css'); - Requirements::javascript('/resources/jaedb/search/client/Search.js'); + Requirements::css('/resources/plasticstudio/search/client/Search.css'); + Requirements::javascript('/resources/plasticstudio/search/client/Search.js'); } // get the parameters and variables of this request (ie the query and filters) @@ -327,7 +327,7 @@ public function PerformSearch(){ $tables_to_check[] = $type['Table']; foreach ($tables_to_check as $table_to_check){ - $column_exists_query = DB::query( "SHOW COLUMNS FROM \"".$table_to_check."\" LIKE '".$filter['Column']."'" ); + $column_exists_query = DB::query( "SHOW COLUMNS FROM \"".$table_to_check."\" LIKE '".$filter['Column']."'" ); foreach ($column_exists_query as $column){ $table_with_column = $table_to_check; @@ -426,9 +426,8 @@ public function PerformSearch(){ $filter_join = $filter['JoinTables'][$type['Key']]; - $joins.= "LEFT JOIN \"".$filter_join['Table']."\" ON \"".$type['Table']."\".\"ID\" = \"".$filter_join['Column']."\""; $joins.= "LEFT JOIN \"".$filter_join['Table']."\" ON \"".$type['Table']."\".\"ID\" = \"".$filter_join['Table']."\".\"".$filter_join['Column']."\""; - + if (is_array($filter['Value'])){ $ids = ''; foreach ($filter['Value'] as $id){ @@ -463,7 +462,7 @@ public function PerformSearch(){ $sql.= $where; // Debugging - //echo '

'.$sql.'

'; + //echo '

'.str_replace('"', '`', $sql).'

'; // Eexecutioner enter stage left $results = DB::query($sql); @@ -486,14 +485,18 @@ public function PerformSearch(){ } // Apply sorting - $sort = self::get_mapped_sort()['Sort']; - $sort = str_replace("'", "\'", $sort); - $sort = str_replace('"', '\"', $sort); - $sort = str_replace('`', '\`', $sort); + if(isset(self::get_mapped_sort()['Sort'])){ + $sort = self::get_mapped_sort()['Sort']; + $sort = str_replace("'", "\'", $sort); + $sort = str_replace('"', '\"', $sort); + $sort = str_replace('`', '\`', $sort); + }else{ + $sort = 'Title ASC'; + } $allResults = $allResults->Sort($sort); // Remove duplicates - //$allResults->removeDuplicates('ID'); + $allResults->removeDuplicates('ID'); // load into a paginated list. To change the items per page, set via the template (ie Results.setPageLength(20)) $paginatedItems = PaginatedList::create($allResults, $this->request);