]> git.joonet.de Git - adminer.git/commitdiff
Fix global search in all tables
authorPeter Knut <peter@pematon.com>
Sun, 4 Apr 2021 22:13:07 +0000 (00:13 +0200)
committerJakub Vrana <jakub@vrana.cz>
Wed, 19 Feb 2025 10:16:35 +0000 (11:16 +0100)
adminer/db.inc.php
adminer/drivers/elastic.inc.php
adminer/include/driver.inc.php

index 6c879fceee3161918036e9125183307bc6616ca8..4b3974ec8143995b241ad5450693ef95508b5fb7 100644 (file)
@@ -61,7 +61,7 @@ if ($adminer->homepage()) {
                                echo " <input type='submit' name='search' value='" . lang('Search') . "'>\n";
                                echo "</div></fieldset>\n";
                                if ($_POST["search"] && $_POST["query"] != "") {
-                                       $_GET["where"][0]["op"] = "LIKE %%";
+                                       $_GET["where"][0]["op"] = $driver->convertOperator("LIKE %%");
                                        search_tables();
                                }
                        }
index b824a3d7baea48dbc1753a9bb0e68791ca9f1fdc..14f3ea6cc4b05ba4b21a87e45ee0f75811fd316c 100644 (file)
@@ -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();
        }
index 99582bd4e2b5ce74d2764bcc1cc1bb607d11e685..bdee7a8d85eb625c033ad51f9fd7a85256eae85c 100644 (file)
@@ -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