Elasticsearch: adapt select() to use $where

This commit is contained in:
Gargaj 2014-09-06 03:24:03 +02:00 committed by Jakub Vrana
parent 02e574c8e9
commit 8d432beb3d

View file

@ -126,17 +126,21 @@ if (isset($_GET["elastic"])) {
$data["from"] = ($page * $limit);
}
}
foreach ((array) $_GET["where"] as $val) {
if ("$val[col]$val[val]" != "") {
$term = array("match" => array(($val["col"] != "" ? $val["col"] : "_all") => $val["val"]));
if ($val["op"] == "=") {
foreach ($where as $val) {
list($col,$op,$val) = explode(" ",$val,3);
if ($col == "_id") {
$data["query"]["ids"]["values"][] = $val;
}
elseif ($col . $val != "") {
$term = array("term" => array(($col != "" ? $col : "_all") => $val));
if ($op == "=") {
$data["query"]["filtered"]["filter"]["and"][] = $term;
} else {
$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());
}
$start = microtime(true);
@ -150,6 +154,9 @@ if (isset($_GET["elastic"])) {
$return = array();
foreach ($search['hits']['hits'] as $hit) {
$row = array();
if ($select == array("*")) {
$row["_id"] = $hit["_id"];
}
$fields = $hit['_source'];
if ($select != array("*")) {
$fields = array();
@ -292,6 +299,10 @@ if (isset($_GET["elastic"])) {
"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"]);
}
}
}
}