Skip to content

Commit

Permalink
Add setMinScore to builder and driver
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Nash committed Feb 6, 2018
1 parent af1d82a commit e3bf9c0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ public function delete($type, $id)
return $this;
}

/**
* Set the minimum score of the query
*
* @param float $score
* @return $this
*/
public function setMinScore($score)
{
$this->driver->setMinScore($score);
return $this;
}

/**
* Create a new query object.
*
Expand Down
8 changes: 8 additions & 0 deletions src/Contracts/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public function add($type, $id, array $data);
*/
public function addMultiple($type, array $data);

/**
* Set the minimum score of the query
*
* @param float $score
* @return $this
*/
public function setMinScore($score);

/**
* Delete a document from the provided type.
*
Expand Down
8 changes: 8 additions & 0 deletions src/Contracts/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,12 @@ public function addMultiple($type, array $data);
* @return Driver
*/
public function delete($type, $id);

/**
* Set the minimum score of the query
*
* @param float $score
* @return $this
*/
public function setMinScore($score);
}
25 changes: 25 additions & 0 deletions src/Drivers/ElasticaDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class ElasticaDriver implements Driver
*/
protected $config;

/**
* The minimum score
*
* @var float
*/
protected $minScore;

public function __construct(Client $client, Index $index, array $config)
{
$this->client = $client;
Expand All @@ -68,7 +75,12 @@ public function get($types, array $queries)
$search = $this->newSearch($types);
$query = $this->newQuery($queries);

if ($this->minScore) {
$query->setMinScore($this->minScore);
}

$query->setSize($this->config['size']);

$search->setQuery($query);

return $this->newResultCollection($search->search());
Expand Down Expand Up @@ -331,6 +343,19 @@ public function wildcard($key = '', $value = null, $boost = 1.0, callable $callb
return $this->returnQuery($query, $callback);
}

/**
* Set the minimum score of the query
*
* @param float $score
* @return $this
*/
public function setMinScore($score)
{
$this->minScore = $score;

return $this;
}

/**
* Create a new search.
*
Expand Down

0 comments on commit e3bf9c0

Please sign in to comment.