Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUGFIX Updating SQLite3Database::searchEngine() for SS3

  • Loading branch information...
commit 43433fbe466218dfa95b9266c6ab01cd67c77c10 1 parent ecda380
@halkyon halkyon authored
Showing with 53 additions and 28 deletions.
  1. +53 −28 code/SQLite3Database.php
View
81 code/SQLite3Database.php
@@ -903,27 +903,58 @@ public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $
$baseClasses = array('SiteTree' => '', 'File' => '');
$queries = array();
foreach($classesToSearch as $class) {
- // SS 2.4 and 3.0
- if(class_exists('DataList')) {
- $queries[$class] = DataList::create($class)->where($notMatch . $match[$class] . $extraFilters[$class], "")->dataQuery()->query();
- } else {
- $queries[$class] = singleton($class)->extendedSQL($notMatch . $match[$class] . $extraFilters[$class], "");
- }
- $baseClasses[$class] = reset($queries[$class]->from);
+ $queries[$class] = DataList::create($class)->where($notMatch . $match[$class] . $extraFilters[$class], "")->dataQuery()->query();
+ $fromArr = $queries[$class]->getFrom();
+ $baseClasses[$class] = reset($fromArr);
}
// Make column selection lists
$select = array(
- 'SiteTree' => array("\"ClassName\"","\"SiteTree\".\"ID\"","\"ParentID\"", "\"Title\"","\"URLSegment\"", "\"Content\"","\"LastEdited\"","\"Created\"","NULL AS \"Filename\"", "NULL AS \"Name\"", "\"CanViewType\"", "$relevance[SiteTree] AS Relevance"),
- 'File' => array("\"ClassName\"","\"File\".\"ID\"", "NULL AS \"ParentID\"","\"Title\"","NULL AS \"URLSegment\"","\"Content\"","\"LastEdited\"","\"Created\"","\"Filename\"", "\"Name\"", "NULL AS \"CanViewType\"", "$relevance[File] AS Relevance"),
+ 'SiteTree' => array(
+ "\"ClassName\"",
+ "\"ID\"",
+ "\"ParentID\"",
+ "\"Title\"",
+ "\"URLSegment\"",
+ "\"Content\"",
+ "\"LastEdited\"",
+ "\"Created\"",
+ "NULL AS \"Filename\"",
+ "NULL AS \"Name\"",
+ "\"CanViewType\"",
+ "$relevance[SiteTree] AS Relevance"
+ ),
+ 'File' => array(
+ "\"ClassName\"",
+ "\"ID\"",
+ "NULL AS \"ParentID\"",
+ "\"Title\"",
+ "NULL AS \"URLSegment\"",
+ "\"Content\"",
+ "\"LastEdited\"",
+ "\"Created\"",
+ "\"Filename\"",
+ "\"Name\"",
+ "NULL AS \"CanViewType\"",
+ "$relevance[File] AS Relevance"
+ )
);
// Process queries
foreach($classesToSearch as $class) {
// There's no need to do all that joining
- $queries[$class]->from = array(str_replace('`','',$baseClasses[$class]) => $baseClasses[$class]);
- $queries[$class]->select = $select[$class];
- $queries[$class]->orderby = null;
+ $queries[$class]->setFrom($baseClasses[$class]);
+
+ $queries[$class]->setSelect(array());
+ foreach($select[$class] as $clause) {
+ if(preg_match('/^(.*) +AS +"?([^"]*)"?/i', $clause, $matches)) {
+ $queries[$class]->selectField($matches[1], $matches[2]);
+ } else {
+ $queries[$class]->selectField(str_replace('"', '', $clause));
+ }
+ }
+
+ $queries[$class]->setOrderBy(array());
}
// Combine queries
@@ -933,28 +964,22 @@ public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $
$querySQLs[] = $query->sql();
$totalCount += $query->unlimitedRowCount();
}
+
$fullQuery = implode(" UNION ", $querySQLs) . " ORDER BY $sortBy LIMIT $limit";
// Get records
$records = DB::query($fullQuery);
- foreach($records as $record)
+ foreach($records as $record) {
$objects[] = new $record['ClassName']($record);
-
- // SS3
- if(class_exists('PaginatedList')) {
- if(isset($objects)) $doSet = new ArrayList($objects);
- else $doSet = new ArrayList();
- $list = new PaginatedList($doSet);
- $list->setPageStart($start);
- $list->setPageLEngth($pageLength);
- $list->setTotalItems($totalCount);
- return $list;
- } else {
- if(isset($objects)) $doSet = new DataObjectSet($objects);
- else $doSet = new DataObjectSet();
- $doSet->setPageLimits($start, $pageLength, $totalCount);
- return $doSet;
}
+
+ if(isset($objects)) $doSet = new ArrayList($objects);
+ else $doSet = new ArrayList();
+ $list = new PaginatedList($doSet);
+ $list->setPageStart($start);
+ $list->setPageLEngth($pageLength);
+ $list->setTotalItems($totalCount);
+ return $list;
}
/*
Please sign in to comment.
Something went wrong with that request. Please try again.