Skip to content

Commit

Permalink
Merge pull request #21 from byng-systems/development_add_terms_query
Browse files Browse the repository at this point in the history
Added support for terms queries
  • Loading branch information
asim-inviqa authored Jun 23, 2016
2 parents e7a0956 + 5bdbf86 commit 18e2b46
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "byng/pimcore-elasticsearch-plugin",
"description": "Elasticsearch Pimcore plugin",
"version": "2.3.0",
"version": "2.4.0",
"type": "pimcore-plugin",
"license": "MIT",
"keywords": [ "pimcore", "elasticsearch", "plugin" ],
Expand Down
6 changes: 6 additions & 0 deletions lib/Byng/Pimcore/Elasticsearch/Gateway/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Byng\Pimcore\Elasticsearch\Model\ResultsList;
use Byng\Pimcore\Elasticsearch\Query\BoolQuery;
use Byng\Pimcore\Elasticsearch\Query\MatchQuery;
use Byng\Pimcore\Elasticsearch\Query\TermsQuery;
use Byng\Pimcore\Elasticsearch\Query\Query;
use Elasticsearch\Client;

Expand Down Expand Up @@ -218,6 +219,11 @@ protected function processQuery(Query $query)
"operator" => $query->getOperator()
];
break;
case "terms":
/** @var TermsQuery $query */
$result = [];
$result["terms"][$query->getField()] = $query->getTerms();
break;
case "range":
$result = [];
$result["range"][$query->getField()] = $query->getRanges();
Expand Down
74 changes: 74 additions & 0 deletions lib/Byng/Pimcore/Elasticsearch/Query/TermsQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/**
* This file is part of the "byng/pimcore-elasticsearch-plugin" project.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the LICENSE is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Byng\Pimcore\Elasticsearch\Query;

/**
* Terms Query
*
* Encapsulates a "terms" query's data.
*
* @author Asim Liaquat <[email protected]>
*/
final class TermsQuery implements Query
{
/**
* @var string
*/
private $field;

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

/**
* TermsQuery constructor.
*
* @param string $field
* @param array $terms
*/
public function __construct($field, array $terms)
{
$this->field = $field;
$this->terms = $terms;
}

/**
* Get field
*
* @return string
*/
public function getField()
{
return $this->field;
}

/**
* Get query
*
* @return array
*/
public function getTerms()
{
return $this->terms;
}

/**
* {@inheritdoc}
*/
public function getType()
{
return "terms";
}
}

0 comments on commit 18e2b46

Please sign in to comment.