-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch: Updated sorting to allow specifying unmapped_type option. (#38)
- Loading branch information
Showing
3 changed files
with
54 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
use Byng\Pimcore\Elasticsearch\Query\QueryInterface; | ||
|
||
/** | ||
* | ||
* | ||
* QueryBuilder defines the query to send to elasticsearch. | ||
* | ||
* @author Asim Liaquat <[email protected]> | ||
|
@@ -27,12 +27,12 @@ class QueryBuilder | |
* @var Query | ||
*/ | ||
private $query; | ||
|
||
/** | ||
* @var Filter | ||
*/ | ||
private $filter; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
|
@@ -42,15 +42,15 @@ class QueryBuilder | |
* @var int | ||
*/ | ||
private $from; | ||
|
||
/** | ||
* @var Sort | ||
*/ | ||
private $sort; | ||
|
||
/** | ||
* QueryBuilder constructor | ||
* | ||
* | ||
* @param Query $query | ||
* @param Filter $filter | ||
*/ | ||
|
@@ -62,7 +62,7 @@ public function __construct(Query $query = null, Filter $filter = null) | |
|
||
/** | ||
* Get query | ||
* | ||
* | ||
* @return Query | ||
*/ | ||
public function getQuery() | ||
|
@@ -72,7 +72,7 @@ public function getQuery() | |
|
||
/** | ||
* Get filter | ||
* | ||
* | ||
* @return Filter | ||
*/ | ||
public function getFilter() | ||
|
@@ -82,7 +82,7 @@ public function getFilter() | |
|
||
/** | ||
* Set query | ||
* | ||
* | ||
* @param Query $query | ||
*/ | ||
public function setQuery(Query $query) | ||
|
@@ -92,7 +92,7 @@ public function setQuery(Query $query) | |
|
||
/** | ||
* Set filter | ||
* | ||
* | ||
* @param Filter $filter | ||
*/ | ||
public function setFilter(Filter $filter) | ||
|
@@ -102,7 +102,7 @@ public function setFilter(Filter $filter) | |
|
||
/** | ||
* Get the number or results to return | ||
* | ||
* | ||
* @return int | ||
*/ | ||
public function getSize() | ||
|
@@ -112,7 +112,7 @@ public function getSize() | |
|
||
/** | ||
* Set the number of results to return | ||
* | ||
* | ||
* @param int $size | ||
*/ | ||
public function setSize($size) | ||
|
@@ -122,7 +122,7 @@ public function setSize($size) | |
|
||
/** | ||
* Get the offset to fetch the results from | ||
* | ||
* | ||
* @return int|null | ||
*/ | ||
public function getFrom() | ||
|
@@ -132,7 +132,7 @@ public function getFrom() | |
|
||
/** | ||
* Set the offset to fetch the results from | ||
* | ||
* | ||
* @param int $from | ||
*/ | ||
public function setFrom($from) | ||
|
@@ -142,7 +142,7 @@ public function setFrom($from) | |
|
||
/** | ||
* Get sort criteria | ||
* | ||
* | ||
* @return Sort | ||
*/ | ||
public function getSort() | ||
|
@@ -152,7 +152,7 @@ public function getSort() | |
|
||
/** | ||
* Set sort criteria | ||
* | ||
* | ||
* @param Sort $sort | ||
*/ | ||
public function setSort(Sort $sort) | ||
|
@@ -168,27 +168,27 @@ public function setSort(Sort $sort) | |
public function toArray() | ||
{ | ||
$body = []; | ||
|
||
if ($query = $this->getQuery()) { | ||
$body = $this->processQuery($query); | ||
} | ||
|
||
if ($filter = $this->getFilter()) { | ||
$body = array_merge($body, $this->processQuery($filter)); | ||
} | ||
|
||
if ($from = $this->getFrom()) { | ||
$body["from"] = $from; | ||
} | ||
|
||
if ($size = $this->getSize()) { | ||
$body["size"] = $size; | ||
} | ||
|
||
if ($sort = $this->getSort()) { | ||
$body["sort"] = $this->processQuery($sort); | ||
} | ||
|
||
return $body; | ||
} | ||
|
||
|
@@ -202,15 +202,15 @@ public function toArray() | |
protected function processQuery(QueryInterface $query) | ||
{ | ||
switch ($query->getType()) { | ||
|
||
case "query": | ||
$result["query"] = $this->processQuery($query->getBoolQuery()); | ||
break; | ||
|
||
case "filter": | ||
$result["filter"] = $this->processQuery($query->getQuery()); | ||
break; | ||
|
||
case "bool": | ||
$boolResult = []; | ||
|
||
|
@@ -230,10 +230,10 @@ protected function processQuery(QueryInterface $query) | |
$result["bool"] = $boolResult; | ||
|
||
break; | ||
|
||
case "match": | ||
$result = []; | ||
|
||
if ($operator = $query->getOperator()) { | ||
$result["match"][$query->getField()] = [ | ||
"query" => $query->getQuery(), | ||
|
@@ -243,16 +243,16 @@ protected function processQuery(QueryInterface $query) | |
$result["match"][$query->getField()] = $query->getQuery(); | ||
} | ||
break; | ||
|
||
case "range": | ||
$result = []; | ||
$result["range"][$query->getField()] = $query->getRanges(); | ||
break; | ||
|
||
case "sort": | ||
$result = []; | ||
foreach ($query->getCriteria() as $column => $order) { | ||
$result[$column]["order"] = $order; | ||
foreach ($query->getCriteria() as $sorting) { | ||
$result[] = $sorting; | ||
} | ||
break; | ||
|
||
|
@@ -261,7 +261,7 @@ protected function processQuery(QueryInterface $query) | |
$query->getField() => $query->getTerms() | ||
]; | ||
break; | ||
|
||
case "prefix": | ||
$result["prefix"] = [ | ||
$query->getField() => $query->getQuery() | ||
|
@@ -279,18 +279,18 @@ protected function processQuery(QueryInterface $query) | |
$query->getField() => $query->getQuery() | ||
]; | ||
break; | ||
|
||
case "constant_score": | ||
$result["constant_score"] = $this->processQuery($query->getFilter()); | ||
break; | ||
|
||
case "nested": | ||
$result["nested"] = [ | ||
"path" => $query->getPath(), | ||
"query" => $this->processQuery($query->getQuery()) | ||
]; | ||
break; | ||
|
||
default: | ||
throw new \InvalidArgumentException(sprintf( | ||
"Unknown query type '%s' given.", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters