Skip to content
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Name: search
Before:
- '#site'
---
Jaedb\Search\SearchPageController:
PlasticStudio\Search\SearchPageController:
types:
docs:
Label: 'Documents'
Expand Down
4 changes: 2 additions & 2 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -13,7 +13,7 @@
}
],
"support": {
"issues": "http://github.com/jaedb/search/issues"
"issues": "http://github.com/plasticstudio/search/issues"
},
"extra": {
"expose": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/SearchControllerExtension.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Jaedb\Search;
namespace PlasticStudio\Search;

use Exception;
use SilverStripe\ORM\DataExtension;
Expand Down
2 changes: 1 addition & 1 deletion src/SearchPage.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Jaedb\Search;
namespace PlasticStudio\Search;

use Page;

Expand Down
41 changes: 24 additions & 17 deletions src/SearchPageController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Jaedb\Search;
namespace PlasticStudio\Search;

use PageController;
use SilverStripe\ORM\ArrayList;
Expand All @@ -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)
Expand Down Expand Up @@ -59,7 +59,7 @@ public function index($request){
**/

public static function get_types_available(){
$types = Config::inst()->get('Jaedb\Search\SearchPageController', 'types');
$types = Config::inst()->get('PlasticStudio\Search\SearchPageController', 'types');
$array = [];

if ($types){
Expand All @@ -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){
Expand All @@ -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){
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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){
Expand All @@ -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 .")";
}

Expand All @@ -459,7 +462,7 @@ public function PerformSearch(){
$sql.= $where;

// Debugging
//echo '<h3 style="position: relative; padding: 20px; background: #EEEEEE; z-index: 999;">'.$sql.'</h3>';
//echo '<h3 style="position: relative; padding: 20px; background: #EEEEEE; z-index: 999;">'.str_replace('"', '`', $sql).'</h3>';

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