From dc1ad9e8ed4674c15860cc017c90f97b77902a5f Mon Sep 17 00:00:00 2001 From: Peter Knut Date: Mon, 5 Apr 2021 00:13:07 +0200 Subject: [PATCH] Fix global search in all tables --- adminer/db.inc.php | 2 +- adminer/drivers/elastic.inc.php | 20 +++++++++++++++++++- adminer/include/driver.inc.php | 8 ++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/adminer/db.inc.php b/adminer/db.inc.php index 6c879fce..4b3974ec 100644 --- a/adminer/db.inc.php +++ b/adminer/db.inc.php @@ -61,7 +61,7 @@ if ($adminer->homepage()) { echo " \n"; echo "\n"; if ($_POST["search"] && $_POST["query"] != "") { - $_GET["where"][0]["op"] = "LIKE %%"; + $_GET["where"][0]["op"] = $driver->convertOperator("LIKE %%"); search_tables(); } } diff --git a/adminer/drivers/elastic.inc.php b/adminer/drivers/elastic.inc.php index b824a3d7..14f3ea6c 100644 --- a/adminer/drivers/elastic.inc.php +++ b/adminer/drivers/elastic.inc.php @@ -57,6 +57,14 @@ if (isset($_GET["elastic"])) { * @return mixed */ function query($path, $content = array(), $method = 'GET') { + // Support for global search through all tables + if ($path != "" && $path[0] == "S" && preg_match('/SELECT 1 FROM ([^ ]+) WHERE (.+) LIMIT ([0-9]+)/', $path, $matches)) { + global $driver; + + $where = explode(" AND ", $matches[2]); + + return $driver->select($matches[1], array("*"), $where, null, array(), $matches[3]); + } return $this->rootQuery(($this->_db != "" ? "$this->_db/" : "/") . ltrim($path, '/'), $content, $method); } @@ -97,7 +105,9 @@ if (isset($_GET["elastic"])) { } function fetch_row() { - return array_values($this->fetch_assoc()); + $row = $this->fetch_assoc(); + + return $row ? array_values($row) : false; } } @@ -231,6 +241,10 @@ if (isset($_GET["elastic"])) { } return $this->_conn->affected_rows; } + + function convertOperator($operator) { + return $operator == "LIKE %%" ? "should" : $operator; + } } @@ -268,6 +282,10 @@ if (isset($_GET["elastic"])) { return $return; } + function limit($query, $where, $limit, $offset = 0, $separator = " ") { + return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); + } + function collations() { return array(); } diff --git a/adminer/include/driver.inc.php b/adminer/include/driver.inc.php index 99582bd4..bdee7a8d 100644 --- a/adminer/include/driver.inc.php +++ b/adminer/include/driver.inc.php @@ -142,6 +142,14 @@ function add_driver($id, $name) { return $idf; } + /** Convert operator so it can be used in search + * @param string $operator + * @return string + */ + function convertOperator($operator) { + return $operator; + } + /** Convert value returned by database to actual value * @param string * @param array