Skip to content

Instantly share code, notes, and snippets.

@martinamps
Created June 24, 2015 21:38
Show Gist options
  • Save martinamps/73d150e9dcda4c77d451 to your computer and use it in GitHub Desktop.
Save martinamps/73d150e9dcda4c77d451 to your computer and use it in GitHub Desktop.
enum Attribute: string {
UINT = 'sql_attr_uint';
BOOL = 'sql_attr_bool';
BIGINT = 'sql_attr_bigint';
TIMESTAMP = 'sql_attr_timestamp';
STR2ORDINAL = 'sql_attr_str2ordinal';
FLOAT = 'sql_attr_float';
MULTI = 'sql_attr_multi';
STRING = 'sql_attr_string';
STR2WORDCOUNT = 'sql_attr_str2wordcount';
}
enum Field: string {
STRING = 'sql_field_string';
STR2WORDCOUNT = 'sql_field_str2wordcount';
}
abstract class Source {
private string $name;
private Map<string, mixed> $params = Map {
'type' => 'plain',
'docinfo' => 'extern'
};
private Vector<Pair<Attribute, string>> $attributes;
private Vector<Pair<Field, string>> $fields;
public function __construct() {
$this->name = __CLASS__;
$this->params['path'] = "/data/{$this->name}/index";
}
public function __set(string $key, mixed $val) : void {
$this->params[$key] = $val;
}
public function __isset(string $key) : bool {
return isset($this->params[$key]);
}
public function __get(string $key) : mixed {
if (isset($this->params[$key])) {
return $this->params[$key];
}
throw new \OutOfBoundsException("Invalid key passed to Sphinx\Sources\{this->name}::__get");
}
public function __unset(string $key) : Map<string, mixed> {
return $this->params->remove($key);
}
public function __toString() : string /* duh */ {
$output = '';
foreach ($this->params as $key => $val) {
$output .= "$key $val\n";
}
return $output;
}
public function addAttribute(Attribute $type, string $column) {
$this->attributes[] = Pair {$type, $column };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment