mirror of
https://github.com/vrana/adminer.git
synced 2025-08-10 16:44:17 +02:00
Replace deprecated "filtered" query with "bool" query
- Allow to choose "must", "should", "must_not" condition. - Add system "_id" column to the field list. So it can be used in search condition.
This commit is contained in:
@@ -111,7 +111,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
|
function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
|
||||||
global $adminer;
|
global $adminer;
|
||||||
$data = array();
|
$data = array();
|
||||||
$query = "$table/_search";
|
$query = (min_version(6) ? "" : "$table/") . "_search";
|
||||||
if ($select != array("*")) {
|
if ($select != array("*")) {
|
||||||
$data["fields"] = $select;
|
$data["fields"] = $select;
|
||||||
}
|
}
|
||||||
@@ -131,21 +131,15 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
foreach ($where as $val) {
|
foreach ($where as $val) {
|
||||||
list($col, $op, $val) = explode(" ", $val, 3);
|
list($col, $op, $val) = explode(" ", $val, 3);
|
||||||
if ($col == "_id") {
|
if ($col . $val != "") {
|
||||||
$data["query"]["ids"]["values"][] = $val;
|
$term = array(($col != "" ? $col : "_all") => $val);
|
||||||
}
|
|
||||||
elseif ($col . $val != "") {
|
|
||||||
$term = array("term" => array(($col != "" ? $col : "_all") => $val));
|
|
||||||
if ($op == "=") {
|
if ($op == "=") {
|
||||||
$data["query"]["filtered"]["filter"]["and"][] = $term;
|
$data["query"]["bool"]["filter"][] = array("term" => $term);
|
||||||
} else {
|
} elseif (in_array($op, array("must", "should", "must_not"))) {
|
||||||
$data["query"]["filtered"]["query"]["bool"]["must"][] = $term;
|
$data["query"]["bool"][$op][]["match"] = $term;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($data["query"] && !$data["query"]["filtered"]["query"] && !$data["query"]["ids"]) {
|
|
||||||
$data["query"]["filtered"]["query"] = array("match_all" => array());
|
|
||||||
}
|
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
$search = $this->_conn->query($query, $data);
|
$search = $this->_conn->query($query, $data);
|
||||||
if ($print) {
|
if ($print) {
|
||||||
@@ -164,7 +158,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
if ($select != array("*")) {
|
if ($select != array("*")) {
|
||||||
$fields = array();
|
$fields = array();
|
||||||
foreach ($select as $key) {
|
foreach ($select as $key) {
|
||||||
$fields[$key] = $hit['fields'][$key];
|
$fields[$key] = $key == "_id" ? [$hit["_id"]] : $hit['fields'][$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($fields as $key => $val) {
|
foreach ($fields as $key => $val) {
|
||||||
@@ -362,19 +356,29 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$return = array();
|
$return = array(
|
||||||
if ($mappings) {
|
"_id" => array(
|
||||||
foreach ($mappings as $name => $field) {
|
"field" => "_id",
|
||||||
$return[$name] = array(
|
"full_type" => "text",
|
||||||
"field" => $name,
|
"type" => "text",
|
||||||
"full_type" => $field["type"],
|
"privileges" => array("insert" => 1, "select" => 1),
|
||||||
"type" => $field["type"],
|
)
|
||||||
"privileges" => array("insert" => 1, "select" => 1, "update" => 1),
|
);
|
||||||
);
|
|
||||||
if ($field["properties"]) { // only leaf fields can be edited
|
foreach ($mappings as $name => $field) {
|
||||||
unset($return[$name]["privileges"]["insert"]);
|
$return[$name] = array(
|
||||||
unset($return[$name]["privileges"]["update"]);
|
"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;
|
return $return;
|
||||||
@@ -477,7 +481,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
return array(
|
return array(
|
||||||
'possible_drivers' => array("json + allow_url_fopen"),
|
'possible_drivers' => array("json + allow_url_fopen"),
|
||||||
'jush' => "elastic",
|
'jush' => "elastic",
|
||||||
'operators' => array("=", "query"),
|
'operators' => array("=", "must", "should", "must_not"),
|
||||||
'functions' => array(),
|
'functions' => array(),
|
||||||
'grouping' => array(),
|
'grouping' => array(),
|
||||||
'edit_functions' => array(array("json")),
|
'edit_functions' => array(array("json")),
|
||||||
|
Reference in New Issue
Block a user