diff --git a/src/mnshankar/Sphinxql/Sphinxql.php b/src/mnshankar/Sphinxql/Sphinxql.php index bb855d2..7b16cfc 100644 --- a/src/mnshankar/Sphinxql/Sphinxql.php +++ b/src/mnshankar/Sphinxql/Sphinxql.php @@ -2,11 +2,11 @@ namespace mnshankar\Sphinxql; class Sphinxql { - protected $library; + protected $library; protected $hits; public function __construct(\Foolz\SphinxQL\SphinxQL $library) { - $this->library = $library; + $this->library = $library; } /** * return the library SphinxQL object for chaining other calls @@ -14,11 +14,19 @@ public function __construct(\Foolz\SphinxQL\SphinxQL $library) */ public function query() { - return $this->library->forge($this->library->getConnection()); + return $this->library->forge($this->library->getConnection()); + } + /** + * return the library SphinxQL helper object + * @return \Foolz\SphinxQL\Helper + */ + public function helper() + { + return \Foolz\SphinxQL\Helper::create($this->library->getConnection()); } /** * set the hits array - * @param array $hits - the array returned by executing the SphinxQL + * @param array $hits - the array returned by executing the SphinxQL * @return \mnshankar\Sphinxql\Sphinxql */ public function with($hits) @@ -27,7 +35,7 @@ public function with($hits) return $this; } /** - * if name is null, return id's + * if name is null, return id's * if name is class (model) return model->get() * if name is table return table->get() * @param string $name @@ -35,28 +43,46 @@ public function with($hits) * @return mixed (either array or eloquentcollection) */ public function get($name=null, $key='id') - { - $matchids = array_pluck($this->hits, $key); + { + $matchids = array_pluck($this->hits, $key); if ($name===null) { return $matchids; - } + } if (class_exists($name)) - { - $result = call_user_func_array($name . "::whereIn", array($key, $matchids))->get(); + { + $result = call_user_func_array($name . "::whereIn", array($key, $matchids))->get(); } - else + else { $result = \DB::table($name)->whereIn($key, $matchids)->get(); - } + } return $result; - } + } /** - * Execute raw query against the sphinx server + * Execute raw query against the sphinx server * @param string $query */ public function raw( $query ) { - return $this->library->getConnection()->query($query); + return $this->library->getConnection()->query($query); + } + /** + * avoids having the expressions escaped + * @param string $string the string to keep unaltered + * @return \Foolz\SphinxQL\Expression the new Expression + */ + public static function expr($string) + { + return \Foolz\SphinxQL\SphinxQL::expr($string); + } + /** + * escapes the input with \MySQLi::real_escape_string + * @param string $value the string to escape + * @return string the escaped string + */ + public function escape($value) + { + return $this->library->getConnection()->escape($value); } -} \ No newline at end of file +}