Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedhafezqo committed Nov 29, 2018
2 parents 20d821b + de50a8f commit a9fe25b
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/Builders/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Elastica\Query\Term;
use Elastica\Query\Terms;
use ElasticRepository\Factory\QueryFactory;
use Elastica\Query\GeoDistance;

class QueryBuilder implements SearchInRangeContract, SearchContract
{
Expand Down Expand Up @@ -74,6 +75,12 @@ class QueryBuilder implements SearchInRangeContract, SearchContract
/**@var array $match */
protected $match = [];

/**@var array $mismatch */
protected $mismatch = [];

/**@var array $geoDistance */
protected $geoDistance = [];

/**
* @var array $simpleQueryString
*/
Expand Down Expand Up @@ -238,6 +245,31 @@ public function match($attribute, $keyword)
return $this;
}

/**
* mismatch words to field
* @param $attribute
* @param $keyword
* @return $this
*/
public function mismatch($attribute, $keyword)
{
$this->mismatch[] = [$attribute, $keyword];

return $this;
}

/**
* Geo distance
* @param $key
* @param $location
* @param $distance
* @return $this
*/
public function geoDistance($key, $location, $distance)
{
$this->geoDistance[] = [$key, $location, $distance];
return $this;
}
/**
* SimpleQueryString to Field
* @param $attribute
Expand Down Expand Up @@ -291,6 +323,8 @@ public function resetBuilder()
$this->whereTerms = [];
$this->whereOr = [];
$this->match = [];
$this->mismatch = [];
$this->geoDistance = [];
$this->simpleQueryString = [];
$this->queryString = [];
$this->query = new BoolQuery();
Expand Down Expand Up @@ -357,6 +391,16 @@ public function prepareQuery()
$this->prepareMatchQueries($match);
}

// add mismatcher queries
foreach ($this->mismatch as $mismatch) {
$this->prepareMismatchQueries($mismatch);
}

// add geoDistance queries
foreach ($this->geoDistance as $geoDistance) {
$this->prepareGeoDistanceQueries($geoDistance);
}

// add SimpleQueryString
foreach ($this->simpleQueryString as $query) {
$this->prepareSimpleQueryString($query);
Expand Down Expand Up @@ -497,6 +541,30 @@ private function prepareMatchQueries($match)
$this->filter->addFilter($matcher);
}

/**
* prepare mismatch query
* @param $mismatch
*/
private function prepareMismatchQueries($mismatch)
{
list($attribute, $keyword) = array_pad($mismatch, 2, null);

$mismatcher = new Match();
$mismatcher->setField($attribute, $keyword);
$this->filter->addMustNot($mismatcher);
}

/**
* prepare geoDistance query
* @param $geoDistance
*/
private function prepareGeoDistanceQueries($geoDistance)
{
list($key, $location, $distance) = array_pad($geoDistance, 3, null);
$geoDistance = new GeoDistance($key, $location, $distance);
$this->filter->addFilter($geoDistance);
}

/**
* prepare Simple Query String
* @param $query
Expand Down

0 comments on commit a9fe25b

Please sign in to comment.