Elasticsearch: adapt select() to use $where
This commit is contained in:
parent
02e574c8e9
commit
8d432beb3d
|
@ -126,17 +126,21 @@ if (isset($_GET["elastic"])) {
|
||||||
$data["from"] = ($page * $limit);
|
$data["from"] = ($page * $limit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ((array) $_GET["where"] as $val) {
|
foreach ($where as $val) {
|
||||||
if ("$val[col]$val[val]" != "") {
|
list($col,$op,$val) = explode(" ",$val,3);
|
||||||
$term = array("match" => array(($val["col"] != "" ? $val["col"] : "_all") => $val["val"]));
|
if ($col == "_id") {
|
||||||
if ($val["op"] == "=") {
|
$data["query"]["ids"]["values"][] = $val;
|
||||||
|
}
|
||||||
|
elseif ($col . $val != "") {
|
||||||
|
$term = array("term" => array(($col != "" ? $col : "_all") => $val));
|
||||||
|
if ($op == "=") {
|
||||||
$data["query"]["filtered"]["filter"]["and"][] = $term;
|
$data["query"]["filtered"]["filter"]["and"][] = $term;
|
||||||
} else {
|
} else {
|
||||||
$data["query"]["filtered"]["query"]["bool"]["must"][] = $term;
|
$data["query"]["filtered"]["query"]["bool"]["must"][] = $term;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($data["query"] && !$data["query"]["filtered"]["query"]) {
|
if ($data["query"] && !$data["query"]["filtered"]["query"] && !$data["query"]["ids"]) {
|
||||||
$data["query"]["filtered"]["query"] = array("match_all" => array());
|
$data["query"]["filtered"]["query"] = array("match_all" => array());
|
||||||
}
|
}
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
|
@ -150,6 +154,9 @@ if (isset($_GET["elastic"])) {
|
||||||
$return = array();
|
$return = array();
|
||||||
foreach ($search['hits']['hits'] as $hit) {
|
foreach ($search['hits']['hits'] as $hit) {
|
||||||
$row = array();
|
$row = array();
|
||||||
|
if ($select == array("*")) {
|
||||||
|
$row["_id"] = $hit["_id"];
|
||||||
|
}
|
||||||
$fields = $hit['_source'];
|
$fields = $hit['_source'];
|
||||||
if ($select != array("*")) {
|
if ($select != array("*")) {
|
||||||
$fields = array();
|
$fields = array();
|
||||||
|
@ -292,6 +299,10 @@ if (isset($_GET["elastic"])) {
|
||||||
"type" => $field["type"],
|
"type" => $field["type"],
|
||||||
"privileges" => array("insert" => 1, "select" => 1, "update" => 1),
|
"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"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue