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/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" 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){ @@ -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,8 +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){ @@ -440,6 +440,9 @@ public function PerformSearch(){ $ids = $filter['Value']; } + if ($relations_sql !== ''){ + $relations_sql.= " AND "; + } $relations_sql.= "\"".$filter_join['Table']."\".\"".$filter['Table']."ID\" IN (". $ids .")"; } @@ -459,7 +462,7 @@ public function PerformSearch(){ $sql.= $where; // Debugging - //echo '

'.$sql.'

'; + //echo '

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

'; // Eexecutioner enter stage left $results = DB::query($sql); @@ -482,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);