Skip to content

Commit

Permalink
Added suppot for 'fields' when querying, also had to remove exclusion…
Browse files Browse the repository at this point in the history
… of content in the results for fields to work properly
  • Loading branch information
asimlqt committed Jul 25, 2017
1 parent 8768fec commit e825fac
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/Byng/Pimcore/Elasticsearch/Gateway/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public function query(
$body["sort"] = $this->processQuery($sort);
}

if (is_array($fields = $queryBuilder->getFields())) {
$body["fields"] = $fields;
}

return $this->findBy(
$body,
$additionalOptions,
Expand Down
8 changes: 1 addition & 7 deletions lib/Byng/Pimcore/Elasticsearch/Gateway/AssetGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,6 @@ public function findBy(
array $additionalOptions = [],
array $resultOptions = []
) {
$additionalOptions = array_merge($additionalOptions, [
"_source" => [
"exclude" => [ "*.content" ]
]
]);

$result = $this->doSearch(
$this->client,
$this->index,
Expand All @@ -208,7 +202,7 @@ public function findBy(
// TODO optimize to use list
foreach ($result["hits"]["hits"] as $page) {
$id = (int) $page["_id"];

if (($asset = Asset::getById($id)) instanceof Asset) {
if (isset($resultOptions["raw"]) && $resultOptions["raw"] === true) {
$assets[] = $page;
Expand Down
25 changes: 25 additions & 0 deletions lib/Byng/Pimcore/Elasticsearch/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class QueryBuilder
*/
private $sort;

/**
* @var array
*/
private $fields;

/**
* QueryBuilder constructor
*
Expand Down Expand Up @@ -120,6 +125,22 @@ public function setSize($size)
$this->size = $size;
}

/**
* @return array|null
*/
public function getFields()
{
return $this->fields;
}

/**
* @param array|null $fields
*/
public function setFields($fields)
{
$this->fields = $fields;
}

/**
* Get the offset to fetch the results from
*
Expand Down Expand Up @@ -189,6 +210,10 @@ public function toArray()
$body["sort"] = $this->processQuery($sort);
}

if (is_array($this->fields)) {
$body["fields"] = $this->fields;
}

return $body;
}

Expand Down

0 comments on commit e825fac

Please sign in to comment.