mirror of
https://github.com/WhatCD/Gazelle.git
synced 2025-01-18 04:01:35 +00:00
Empty commit
This commit is contained in:
parent
304a28d6e0
commit
7c8739fe5e
@ -2,6 +2,7 @@
|
||||
class SphinxqlQuery {
|
||||
private $Sphinxql;
|
||||
|
||||
private $Errors;
|
||||
private $Expressions;
|
||||
private $Filters;
|
||||
private $GroupBy;
|
||||
@ -48,7 +49,7 @@ public function from($Indexes) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add attribute filter. Calling this function multiple times results in boolean AND between each condition
|
||||
* Add attribute filter. Calling multiple filter functions results in boolean AND between each condition.
|
||||
*
|
||||
* @param string $Attribute attribute which the filter will apply to
|
||||
* @param mixed $Values scalar or array of numerical values. Array uses boolean OR in query condition
|
||||
@ -56,14 +57,16 @@ public function from($Indexes) {
|
||||
* @return current Sphinxql query object
|
||||
*/
|
||||
public function where($Attribute, $Values, $Exclude = false) {
|
||||
if (empty($Attribute) && empty($Values)) {
|
||||
return false;
|
||||
if (empty($Attribute) || !isset($Values)) {
|
||||
$this->error("Attribute name and filter value are required.");
|
||||
return $this;
|
||||
}
|
||||
$Filters = array();
|
||||
if (is_array($Values)) {
|
||||
foreach ($Values as $Value) {
|
||||
if (!is_number($Value)) {
|
||||
$this->error("Filters require numeric values");
|
||||
$this->error("Filters only support numeric values.");
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
if ($Exclude) {
|
||||
@ -73,7 +76,8 @@ public function where($Attribute, $Values, $Exclude = false) {
|
||||
}
|
||||
} else {
|
||||
if (!is_number($Values)) {
|
||||
$this->error("Filters require numeric values");
|
||||
$this->error("Filters only support numeric values.");
|
||||
return $this;
|
||||
}
|
||||
if ($Exclude) {
|
||||
$Filters[] = "$Attribute != $Values";
|
||||
@ -86,7 +90,41 @@ public function where($Attribute, $Values, $Exclude = false) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add attribute range filter. Calling this function multiple times results in boolean AND between each condition
|
||||
* Add attribute less-than filter. Calling multiple filter functions results in boolean AND between each condition.
|
||||
*
|
||||
* @param string $Attribute attribute which the filter will apply to
|
||||
* @param array $Value upper limit for matches
|
||||
* @param bool $Inclusive whether to use <= or <
|
||||
* @return current Sphinxql query object
|
||||
*/
|
||||
public function where_lt($Attribute, $Value, $Inclusive = false) {
|
||||
if (empty($Attribute) || !isset($Value) || !is_number($Value)) {
|
||||
$this->error("Attribute name is required and only numeric filters are supported.");
|
||||
return $this;
|
||||
}
|
||||
$this->Filters[] = $Inclusive ? "$Attribute <= $Value" : "$Attribute < $Value";
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add attribute greater-than filter. Calling multiple filter functions results in boolean AND between each condition.
|
||||
*
|
||||
* @param string $Attribute attribute which the filter will apply to
|
||||
* @param array $Value lower limit for matches
|
||||
* @param bool $Inclusive whether to use >= or >
|
||||
* @return current Sphinxql query object
|
||||
*/
|
||||
public function where_gt($Attribute, $Value, $Inclusive = false) {
|
||||
if (empty($Attribute) || !isset($Value) || !is_number($Value)) {
|
||||
$this->error("Attribute name is required and only numeric filters are supported.");
|
||||
return $this;
|
||||
}
|
||||
$this->Filters[] = $Inclusive ? "$Attribute >= $Value" : "$Attribute > $Value";
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add attribute range filter. Calling multiple filter functions results in boolean AND between each condition.
|
||||
*
|
||||
* @param string $Attribute attribute which the filter will apply to
|
||||
* @param array $Values pair of numerical values that defines the filter range
|
||||
@ -95,13 +133,14 @@ public function where($Attribute, $Values, $Exclude = false) {
|
||||
public function where_between($Attribute, $Values) {
|
||||
if (empty($Attribute) || empty($Values) || count($Values) != 2 || !is_number($Values[0]) || !is_number($Values[1])) {
|
||||
$this->error("Filter range requires array of two numerical boundaries as values.");
|
||||
return $this;
|
||||
}
|
||||
$this->Filters[] = "$Attribute BETWEEN $Values[0] AND $Values[1]";
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add fulltext query expression. Calling this function multiple times results in boolean AND between each condition.
|
||||
* Add fulltext query expression. Calling multiple filter functions results in boolean AND between each condition.
|
||||
* Query expression is escaped automatically
|
||||
*
|
||||
* @param string $Expr query expression
|
||||
@ -218,6 +257,7 @@ private function build_options() {
|
||||
private function build_query() {
|
||||
if (!$this->Indexes) {
|
||||
$this->error('Index name is required.');
|
||||
return false;
|
||||
}
|
||||
$this->QueryString = "SELECT $this->Select\nFROM $this->Indexes";
|
||||
if (!empty($this->Expressions)) {
|
||||
@ -253,6 +293,11 @@ private function build_query() {
|
||||
public function query($GetMeta = true) {
|
||||
$QueryStartTime = microtime(true);
|
||||
$this->build_query();
|
||||
if (count($this->Errors) > 0) {
|
||||
$ErrorMsg = implode("\n", $this->Errors);
|
||||
$this->Sphinxql->error("Query builder found errors:\n$ErrorMsg");
|
||||
return new SphinxqlResult(null, null, 1, $ErrorMsg);
|
||||
}
|
||||
$QueryString = $this->QueryString;
|
||||
$Result = $this->send_query($GetMeta);
|
||||
$QueryProcessTime = (microtime(true) - $QueryStartTime)*1000;
|
||||
@ -287,7 +332,7 @@ private function send_query($GetMeta) {
|
||||
if ($Result === false) {
|
||||
$Errno = $this->Sphinxql->errno;
|
||||
$Error = $this->Sphinxql->error;
|
||||
$this->error("Query returned error $Errno ($Error).\n$this->QueryString");
|
||||
$this->Sphinxql->error("Query returned error $Errno ($Error).\n$this->QueryString");
|
||||
$Meta = null;
|
||||
} else {
|
||||
$Errno = 0;
|
||||
@ -301,6 +346,7 @@ private function send_query($GetMeta) {
|
||||
* Reset all query options and conditions
|
||||
*/
|
||||
public function reset() {
|
||||
$this->Errors = array();
|
||||
$this->Expressions = array();
|
||||
$this->Filters = array();
|
||||
$this->GroupBy = '';
|
||||
@ -323,9 +369,9 @@ private function get_meta() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the current Sphinxql connection's error function
|
||||
* Store error messages
|
||||
*/
|
||||
private function error($Msg, $Halt = false) {
|
||||
$this->Sphinxql->error($Msg, $Halt);
|
||||
private function error($Msg) {
|
||||
$this->Errors[] = $Msg;
|
||||
}
|
||||
}
|
||||
|
@ -440,16 +440,22 @@ function header_link($SortKey, $DefaultWay = 'desc') {
|
||||
$Years = explode('-', $_GET['year']);
|
||||
if (is_number($Years[0]) || (empty($Years[0]) && !empty($Years[1]) && is_number($Years[1]))) {
|
||||
if (count($Years) === 1) {
|
||||
$SphQL->where('year', (int)$Years[0]);
|
||||
$SphQLTor->where('year', (int)$Years[0]);
|
||||
$SphQL->where('year', $Years[0]);
|
||||
$SphQLTor->where('year', $Years[0]);
|
||||
} else {
|
||||
if (empty($Years[1]) || !is_number($Years[1])) {
|
||||
$Years[1] = PHP_INT_MAX;
|
||||
} elseif ($Years[0] > $Years[1]) {
|
||||
$Years = array_reverse($Years);
|
||||
if (empty($Years[0])) {
|
||||
$SphQL->where_lt('year', $Years[1], true);
|
||||
$SphQLTor->where_lt('year', $Years[1], true);
|
||||
} elseif (empty($Years[1]) || !is_number($Years[1])) {
|
||||
$SphQL->where_gt('year', $Years[0], true);
|
||||
$SphQLTor->where_gt('year', $Years[0], true);
|
||||
} else {
|
||||
if ($Years[0] > $Years[1]) {
|
||||
$Years = array_reverse($Years);
|
||||
}
|
||||
$SphQL->where_between('year', array($Years[0], $Years[1]));
|
||||
$SphQLTor->where_between('year', array($Years[0], $Years[1]));
|
||||
}
|
||||
$SphQL->where_between('year', array((int)$Years[0], (int)$Years[1]));
|
||||
$SphQLTor->where_between('year', array((int)$Years[0], (int)$Years[1]));
|
||||
}
|
||||
$Filtered = true;
|
||||
}
|
||||
@ -460,10 +466,10 @@ function header_link($SortKey, $DefaultWay = 'desc') {
|
||||
$SphQL->where('logscore', 100);
|
||||
$SphQLTor->where('logscore', 100);
|
||||
} elseif ($_GET['haslog'] < 0) {
|
||||
// Exclude torrents with log score equal to 100
|
||||
$SphQL->where('logscore', 100, true);
|
||||
// Look for torrents with log score < 100
|
||||
$SphQL->where_lt('logscore', 100);
|
||||
$SphQL->where('haslog', 1);
|
||||
$SphQLTor->where('logscore', 100, true);
|
||||
$SphQLTor->where_lt('logscore', 100);
|
||||
$SphQLTor->where('haslog', 1);
|
||||
} elseif ($_GET['haslog'] == 0) {
|
||||
$SphQL->where('haslog', 0);
|
||||
|
Loading…
Reference in New Issue
Block a user