diff --git a/composer.json b/composer.json index 97b3787..ce9a1af 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "sngrl/sphinxsearch", + "name": "biblioonline/sphinxsearch-l5", "description": "Laravel package to query Sphinxsearch in Laravel 5", "keywords": [ "sphinx", @@ -7,17 +7,17 @@ "laravel", "laravel 5" ], - "homepage": "http://github.com/sngrl/sphinxsearch", - "license": "Apache-2.0", + "homepage": "https://github.com/biblioonline/sphinxsearch-l5", + "license": "MIT", "authors": [ { - "name": "sngrl", - "email": "reserved@mail.ru" + "name": "biblioonline", + "email": "danik0072@gmail.com" } ], "require": { "php": ">=5.3.0", - "illuminate/support": "~5.0", + "illuminate/support": "~7.0", "gigablah/sphinxphp": "2.0.8" }, "autoload": { diff --git a/src/sngrl/SphinxSearch/SphinxSearch.php b/src/sngrl/SphinxSearch/SphinxSearch.php index 87ff926..c189c1d 100644 --- a/src/sngrl/SphinxSearch/SphinxSearch.php +++ b/src/sngrl/SphinxSearch/SphinxSearch.php @@ -10,7 +10,7 @@ class SphinxSearch protected $_total_count; protected $_time; protected $_eager_loads; - protected $_raw_mysql_connection; + protected $_raw_mysql_connection; public function __construct() { @@ -31,53 +31,53 @@ public function __construct() $this->_eager_loads = array(); } - /** - * @param $docs - * @param $index_name - * @param $query - * @param array $extra, in this format: array('option_name' => option_value, 'limit' => 100, ...) - * @return array - */ - public function getSnippetsQL($docs, $index_name, $query, $extra = []) - { - // $extra = []; - if (is_array($docs) === FALSE) - { - $docs = [$docs]; - } - foreach ($docs as &$doc) - { - $doc = "'".mysqli_real_escape_string($this->_raw_mysql_connection, strip_tags($doc))."'"; - } + /** + * @param $docs + * @param $index_name + * @param $query + * @param array $extra, in this format: array('option_name' => option_value, 'limit' => 100, ...) + * @return array + */ + public function getSnippetsQL($docs, $index_name, $query, $extra = []) + { + // $extra = []; + if (is_array($docs) === FALSE) + { + $docs = [$docs]; + } + foreach ($docs as &$doc) + { + $doc = "'".mysqli_real_escape_string($this->_raw_mysql_connection, strip_tags($doc))."'"; + } - $extra_ql = ''; - if ($extra) - { - foreach ($extra as $key => $value) - { - $extra_ql[] = $value.' AS '.$key; - } - $extra_ql = implode(',', $extra_ql); - if ($extra_ql) - { - $extra_ql = ','.$extra_ql; - } - } + $extra_ql = ''; + if ($extra) + { + foreach ($extra as $key => $value) + { + $extra_ql[] = $value.' AS '.$key; + } + $extra_ql = implode(',', $extra_ql); + if ($extra_ql) + { + $extra_ql = ','.$extra_ql; + } + } - $query = "CALL SNIPPETS((".implode(',',$docs)."),'".$index_name."','".mysqli_real_escape_string($this->_raw_mysql_connection, $query)."' ".$extra_ql.")"; - // die($query); - $result = mysqli_query($this->_raw_mysql_connection, $query); - // ddd($result); - $reply = array(); - if ($result) - { - while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) - { - $reply[] = $row['snippet']; - } - } - return $reply; - } + $query = "CALL SNIPPETS((".implode(',',$docs)."),'".$index_name."','".mysqli_real_escape_string($this->_raw_mysql_connection, $query)."' ".$extra_ql.")"; + // die($query); + $result = mysqli_query($this->_raw_mysql_connection, $query); + // ddd($result); + $reply = array(); + if ($result) + { + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) + { + $reply[] = $row['snippet']; + } + } + return $reply; + } public function search($string, $index_name = null) { @@ -114,9 +114,9 @@ public function setMatchMode($mode) return $this; } - public function setRankingMode($mode) + public function setRankingMode($mode, $expr = '') { - $this->_connection->setRankingMode($mode); + $this->_connection->setRankingMode($mode, $expr); return $this; } @@ -208,9 +208,9 @@ public function get($respect_sort_order = false) $config = isset($this->_config['mapping']) ? $this->_config['mapping'] : $this->_config[$this->_index_name]; - // Get the model primary key column name - $primaryKey = isset($config['primaryKey']) ? $config['primaryKey'] : 'id'; - + // Get the model primary key column name + $primaryKey = isset($config['primaryKey']) ? $config['primaryKey'] : 'id'; + if ($config) { if (isset($config['repository'])) { $result = call_user_func_array($config['repository'] . '::findInRange', @@ -268,6 +268,11 @@ public function with() return $this; } + public function getSphinxClientInstance() + { + return $this->_connection; + } + public function getTotalCount() { return $this->_total_count;