1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-09 16:17:48 +02:00

Elastic: Prepare for better selecting

This commit is contained in:
Jakub Vrana
2013-08-08 13:21:34 -07:00
parent 114aaec91e
commit e85aff166f

View File

@@ -9,9 +9,10 @@ if (isset($_GET["elastic"])) {
class Min_DB { class Min_DB {
var $extension = "JSON", $server_info, $errno, $error, $_url; var $extension = "JSON", $server_info, $errno, $error, $_url;
function query($path) { function query($path, $content = array()) {
@ini_set('track_errors', 1); // @ - may be disabled @ini_set('track_errors', 1); // @ - may be disabled
$file = @file_get_contents($this->_url . ($this->_db != "" ? "$this->_db/" : "") . $path, false, stream_context_create(array('http' => array( $file = @file_get_contents($this->_url . ($this->_db != "" ? "$this->_db/" : "") . $path, false, stream_context_create(array('http' => array(
'content' => json_encode($content),
'ignore_errors' => 1, // available since PHP 5.2.10 'ignore_errors' => 1, // available since PHP 5.2.10
)))); ))));
if (!$file) { if (!$file) {
@@ -89,21 +90,42 @@ if (isset($_GET["elastic"])) {
function select($table, $select, $where, $group, $order, $limit, $page) { function select($table, $select, $where, $group, $order, $limit, $page) {
global $adminer; global $adminer;
$query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page); $query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
$data = array();
if (!$query) { if (!$query) {
$query = "$table/_search?default_operator=AND" $query = "$table/_search";
. ($select != array("*") ? "&fields=" . urlencode(implode(",", $select)) : "") if ($select != array("*")) {
. ($order ? "&sort=" . urlencode(preg_replace('~ DESC(,|$)~', ':desc\1', implode(",", $order))) : "") $data["fields"] = $select;
. ($limit ? "&size=" . (+$limit) . ($page ? "&from=" . ($page * $limit) : "") : "") // doesn't support returning all results }
; if ($order) {
$sort = array();
foreach ($order as $col) {
$col = preg_replace('~ DESC$~', '', $col, 1, $count);
$sort[] = ($count ? array($col => "desc") : $col);
}
$data["sort"] = $sort;
}
if ($limit) {
$data["size"] = +$limit;
if ($page) {
$data["from"] = ($page * $limit);
}
}
foreach ((array) $_GET["where"] as $val) { foreach ((array) $_GET["where"] as $val) {
if ("$val[col]$val[val]" != "") { if ("$val[col]$val[val]" != "") {
$query .= "&q=" . urlencode(($val["col"] != "" ? "$val[col]:" : "") . $val["val"]); $term = array("match" => array(($val["col"] != "" ? $val["col"] : "_all") => $val["val"]));
//! uses only last condition if ($val["op"] == "=") {
$data["query"]["filtered"]["filter"]["and"][] = $term;
} else {
$data["query"]["filtered"]["query"]["bool"]["must"][] = $term;
}
} }
} }
if ($data["query"] && !$data["query"]["filtered"]["query"]) {
$data["query"]["filtered"]["query"] = array("match_all" => array());
}
} }
echo $adminer->selectQuery($query); echo $adminer->selectQuery($query);
$search = $this->_conn->query($query); $search = $this->_conn->query($query, $data);
if (!$search) { if (!$search) {
return false; return false;
} }
@@ -257,7 +279,7 @@ if (isset($_GET["elastic"])) {
} }
$jush = "elastic"; $jush = "elastic";
$operators = array("="); $operators = array("=", "query");
$functions = array(); $functions = array();
$grouping = array(); $grouping = array();
$edit_functions = array(); $edit_functions = array();