From dd5ec61a0fe709c6cd30ee80ab1f175910e93ed1 Mon Sep 17 00:00:00 2001 From: Alexey Komarov Date: Wed, 15 Jul 2015 15:50:02 +0300 Subject: [PATCH] 1) Fix error with database configuration 'fetch' = PDO::FETCH_ASSOC 2) Use ids as result array keys --- src/Scalia/SphinxSearch/SphinxSearch.php | 25 ++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Scalia/SphinxSearch/SphinxSearch.php b/src/Scalia/SphinxSearch/SphinxSearch.php index 43d1b52..d9734eb 100644 --- a/src/Scalia/SphinxSearch/SphinxSearch.php +++ b/src/Scalia/SphinxSearch/SphinxSearch.php @@ -173,7 +173,21 @@ public function get($respect_sort_order = false) { $result = \DB::table($config['table'])->whereIn($config['column'], $matchids)->orderByRaw(\DB::raw("FIELD(id, $idString)"))->get(); } - + if($result) { + $mode = \Config::get('database.fetch'); + $key4result = array(); + if($mode == \PDO::FETCH_ASSOC) { + foreach($result as $result_item) { + $key4result[$result_item[$config['column']]] = $result_item; + } + } else { + foreach($result as $result_item) { + $key4result[$result_item->$config['column']] = $result_item; + } + } + $result = $key4result; + unset($key4result); + } } } else @@ -189,11 +203,7 @@ public function get($respect_sort_order = false) $return_val = array(); foreach($matchids as $matchid) { - $key = self::getResultKeyByID($matchid, $result); - if (false !== $key) - { - $return_val[] = $result[$key]; - } + $return_val[$matchid] = $result[$matchid]; } return $return_val; } @@ -240,6 +250,9 @@ public function getErrorMessage() return $this->_connection->getLastError(); } + /** + * @deprecated + */ private function getResultKeyByID($id, $result) { if(count($result) > 0)