mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
BUGFIX Fixes to searchEngine() to support SS 3.0 ORM changes
This commit is contained in:
parent
a9444a8313
commit
2312b49b9c
@ -1290,7 +1290,14 @@ class MSSQLDatabase extends SS_Database {
|
|||||||
* @return object DataObjectSet of result pages
|
* @return object DataObjectSet of result pages
|
||||||
*/
|
*/
|
||||||
public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC", $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false) {
|
public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC", $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false) {
|
||||||
$results = new DataObjectSet();
|
if(class_exists('PaginatedList')) {
|
||||||
|
if(isset($objects)) $results = new ArrayList($objects);
|
||||||
|
else $results = new ArrayList();
|
||||||
|
} else {
|
||||||
|
if(isset($objects)) $results = new DataObjectSet($objects);
|
||||||
|
else $results = new DataObjectSet();
|
||||||
|
}
|
||||||
|
|
||||||
if (!$this->fullTextEnabled()) return $results;
|
if (!$this->fullTextEnabled()) return $results;
|
||||||
if (!in_array(substr($sortBy, 0, 9), array('"Relevanc', 'Relevance'))) user_error("Non-relevance sort not supported.", E_USER_ERROR);
|
if (!in_array(substr($sortBy, 0, 9), array('"Relevanc', 'Relevance'))) user_error("Non-relevance sort not supported.", E_USER_ERROR);
|
||||||
|
|
||||||
@ -1321,7 +1328,7 @@ class MSSQLDatabase extends SS_Database {
|
|||||||
$baseClass = ClassInfo::baseDataClass($tableName);
|
$baseClass = ClassInfo::baseDataClass($tableName);
|
||||||
|
|
||||||
$join = $this->fullTextSearchMSSQL($tableName, $keywords);
|
$join = $this->fullTextSearchMSSQL($tableName, $keywords);
|
||||||
if (!$join) return new DataObjectSet(); // avoid "Null or empty full-text predicate"
|
if (!$join) return $results; // avoid "Null or empty full-text predicate"
|
||||||
|
|
||||||
// Check if we need to add ShowInSearch
|
// Check if we need to add ShowInSearch
|
||||||
$where = null;
|
$where = null;
|
||||||
@ -1336,7 +1343,12 @@ class MSSQLDatabase extends SS_Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(class_exists('DataList')) {
|
||||||
|
$queries[$tableName] = DataList::create($tableName)->where($where, '')->dataQuery()->query();
|
||||||
|
} else {
|
||||||
$queries[$tableName] = singleton($tableName)->extendedSQL($where);
|
$queries[$tableName] = singleton($tableName)->extendedSQL($where);
|
||||||
|
}
|
||||||
|
|
||||||
$queries[$tableName]->orderby = null;
|
$queries[$tableName]->orderby = null;
|
||||||
|
|
||||||
// Join with CONTAINSTABLE, a full text searcher that includes relevance factor
|
// Join with CONTAINSTABLE, a full text searcher that includes relevance factor
|
||||||
@ -1370,19 +1382,31 @@ class MSSQLDatabase extends SS_Database {
|
|||||||
|
|
||||||
// Regenerate DataObjectSet - watch out, numRecords doesn't work on sqlsrv driver on Windows.
|
// Regenerate DataObjectSet - watch out, numRecords doesn't work on sqlsrv driver on Windows.
|
||||||
$current = -1;
|
$current = -1;
|
||||||
$results = new DataObjectSet();
|
$objects = array();
|
||||||
foreach ($result as $row) {
|
foreach ($result as $row) {
|
||||||
$current++;
|
$current++;
|
||||||
|
|
||||||
// Select a subset for paging
|
// Select a subset for paging
|
||||||
if ($current >= $start && $current < $start + $pageLength) {
|
if ($current >= $start && $current < $start + $pageLength) {
|
||||||
$results->push(DataObject::get_by_id($row['Source'], $row['ID']));
|
$objects[] = DataObject::get_by_id($row['Source'], $row['ID']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$results->setPageLimits($start, $pageLength, $current+1);
|
|
||||||
|
|
||||||
|
if(class_exists('PaginatedList')) {
|
||||||
|
if(isset($objects)) $results = new ArrayList($objects);
|
||||||
|
else $results = new ArrayList();
|
||||||
|
$list = new PaginatedList($results);
|
||||||
|
$list->setPageStart($start);
|
||||||
|
$list->setPageLength($pageLength);
|
||||||
|
$list->setTotalItems($current+1);
|
||||||
|
return $list;
|
||||||
|
} else {
|
||||||
|
if(isset($objects)) $results = new DataObjectSet($objects);
|
||||||
|
else $results = new DataObjectSet();
|
||||||
|
$results->setPageLimits($start, $pageLength, $current+1);
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow auto-increment primary key editing on the given table.
|
* Allow auto-increment primary key editing on the given table.
|
||||||
|
Loading…
Reference in New Issue
Block a user