]> git.joonet.de Git - adminer.git/commitdiff
Fix searching if "anywhere" field is selected
authorPeter Knut <peter@pematon.com>
Sun, 21 Mar 2021 19:40:43 +0000 (20:40 +0100)
committerJakub Vrana <jakub@vrana.cz>
Wed, 19 Feb 2025 10:16:35 +0000 (11:16 +0100)
- Allow to search only in fields with index.

adminer/drivers/elastic.inc.php

index bf46fdcbb472e6372f396efef92dfc8abc6ac0f5..4f9ce28d7f8b29f4d71705498442339c13abb92f 100644 (file)
@@ -130,9 +130,25 @@ if (isset($_GET["elastic"])) {
                                }
                        }
                        foreach ($where as $val) {
-                               list($col, $op, $val) = explode(" ", $val, 3);
-                               if ($col . $val != "") {
-                                       $term = array(($col != "" ? $col : "_all") => $val);
+                               if (preg_match('~^\((.+ OR .+)\)$~', $val, $matches)) {
+                                       $parts = explode(" OR ", $matches[1]);
+                                       $terms = array();
+                                       foreach ($parts as $part) {
+                                               list($col, $op, $val) = explode(" ", $part, 3);
+                                               $term = array($col => $val);
+                                               if ($op == "=") {
+                                                       $terms[] = array("term" => $term);
+                                               } elseif (in_array($op, array("must", "should", "must_not"))) {
+                                                       $data["query"]["bool"][$op][]["match"] = $term;
+                                               }
+                                       }
+
+                                       if (!empty($terms)) {
+                                               $data["query"]["bool"]["filter"][]["bool"]["should"] = $terms;
+                                       }
+                               } else {
+                                       list($col, $op, $val) = explode(" ", $val, 3);
+                                       $term = array($col => $val);
                                        if ($op == "=") {
                                                $data["query"]["bool"]["filter"][] = array("term" => $term);
                                        } elseif (in_array($op, array("must", "should", "must_not"))) {
@@ -366,19 +382,21 @@ if (isset($_GET["elastic"])) {
                );
 
                foreach ($mappings as $name => $field) {
-                       $return[$name] = array(
-                               "field" => $name,
-                               "full_type" => $field["type"],
-                               "type" => $field["type"],
-                               "privileges" => array(
-                                       "insert" => 1,
-                                       "select" => 1,
-                                       "update" => 1,
-                               ),
-                       );
-                       if ($field["properties"]) { // only leaf fields can be edited
-                               unset($return[$name]["privileges"]["insert"]);
-                               unset($return[$name]["privileges"]["update"]);
+                       if (!isset($field["index"]) || $field["index"]) {
+                               $return[$name] = array(
+                                       "field" => $name,
+                                       "full_type" => $field["type"],
+                                       "type" => $field["type"],
+                                       "privileges" => array(
+                                               "insert" => 1,
+                                               "select" => 1,
+                                               "update" => 1,
+                                       ),
+                               );
+                               if ($field["properties"]) { // only leaf fields can be edited
+                                       unset($return[$name]["privileges"]["insert"]);
+                                       unset($return[$name]["privileges"]["update"]);
+                               }
                        }
                }
                return $return;