Skip to content
Open

V7.0 #47

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
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"name": "sngrl/sphinxsearch",
"name": "biblioonline/sphinxsearch-l5",
"description": "Laravel package to query Sphinxsearch in Laravel 5",
"keywords": [
"sphinx",
"sphinxsearch",
"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": "[email protected]"
"name": "biblioonline",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.3.0",
"illuminate/support": "~5.0",
"illuminate/support": "~7.0",
"gigablah/sphinxphp": "2.0.8"
},
"autoload": {
Expand Down
107 changes: 56 additions & 51 deletions src/sngrl/SphinxSearch/SphinxSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -268,6 +268,11 @@ public function with()
return $this;
}

public function getSphinxClientInstance()
{
return $this->_connection;
}

public function getTotalCount()
{
return $this->_total_count;
Expand Down