From b90a12bfb4a49e362efb2ae9654346211303a867 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Wed, 8 Jan 2014 23:16:51 -0800 Subject: [PATCH] Elasticsearch: Don't use selectQueryBuild() --- adminer/drivers/elastic.inc.php | 55 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/adminer/drivers/elastic.inc.php b/adminer/drivers/elastic.inc.php index 0d289b6f..fa9725dd 100644 --- a/adminer/drivers/elastic.inc.php +++ b/adminer/drivers/elastic.inc.php @@ -90,40 +90,37 @@ if (isset($_GET["elastic"])) { function select($table, $select, $where, $group, $order, $limit, $page, $print = false) { global $adminer; - $query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page); $data = array(); - if (!$query) { - $query = "$table/_search"; - if ($select != array("*")) { - $data["fields"] = $select; + $query = "$table/_search"; + if ($select != array("*")) { + $data["fields"] = $select; + } + if ($order) { + $sort = array(); + foreach ($order as $col) { + $col = preg_replace('~ DESC$~', '', $col, 1, $count); + $sort[] = ($count ? array($col => "desc") : $col); } - if ($order) { - $sort = array(); - foreach ($order as $col) { - $col = preg_replace('~ DESC$~', '', $col, 1, $count); - $sort[] = ($count ? array($col => "desc") : $col); - } - $data["sort"] = $sort; + $data["sort"] = $sort; + } + if ($limit) { + $data["size"] = +$limit; + if ($page) { + $data["from"] = ($page * $limit); } - if ($limit) { - $data["size"] = +$limit; - if ($page) { - $data["from"] = ($page * $limit); + } + foreach ((array) $_GET["where"] as $val) { + if ("$val[col]$val[val]" != "") { + $term = array("match" => array(($val["col"] != "" ? $val["col"] : "_all") => $val["val"])); + if ($val["op"] == "=") { + $data["query"]["filtered"]["filter"]["and"][] = $term; + } else { + $data["query"]["filtered"]["query"]["bool"]["must"][] = $term; } } - foreach ((array) $_GET["where"] as $val) { - if ("$val[col]$val[val]" != "") { - $term = array("match" => array(($val["col"] != "" ? $val["col"] : "_all") => $val["val"])); - 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()); - } + } + if ($data["query"] && !$data["query"]["filtered"]["query"]) { + $data["query"]["filtered"]["query"] = array("match_all" => array()); } if ($print) { echo $adminer->selectQuery("$query: " . print_r($data, true));