Skip to content

Commit

Permalink
add should filter for query string and query string wih fuzzy (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedsallam1 authored Jun 13, 2019
1 parent 7f85dd1 commit 557f5a9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Builders/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ public function simpleQueryString($attribute, $keyword)
* @param string $keyword
* @return $this
*/
public function queryString(array $attributes, string $defaultOperator = null, string $keyword = null)
public function queryString(array $attributes, string $defaultOperator = null, string $keyword = null, $boost = 10)
{
$this->queryString [] =[$attributes, $defaultOperator, $keyword];
$this->queryString [] =[$attributes, $defaultOperator, $keyword, $boost];

return $this;
}
Expand Down Expand Up @@ -429,12 +429,12 @@ public function prepareQuery()

// add QueryString
foreach ($this->queryString as $query) {
$this->prepareQueryString($query);
$this->prepareQueryString($query, $boolOr);
}

// add QueryStringWithFuzzy
foreach ($this->queryStringWithFuzzy as $queryStringWithFuzzy) {
$this->prepareQueryStringWithFuzzy($queryStringWithFuzzy);
$this->prepareQueryStringWithFuzzy($queryStringWithFuzzy, $boolOr);
}

// add BoolOr
Expand Down Expand Up @@ -607,21 +607,22 @@ private function prepareSimpleQueryString($query)
* prepare Simple Query String
* @param $query
*/
private function prepareQueryString($query)
private function prepareQueryString($query, &$boolOr)
{
list($attributes, $defaultOperator, $keyword) = array_pad($query, 3, null);
list($attributes, $defaultOperator, $keyword, $boost) = array_pad($query, 4, null);
$queryString = new QueryString($keyword);
$queryString
->setFields($attributes)
->setDefaultOperator($defaultOperator)
->setBoost($boost)
;
$this->filter->addFilter($queryString);
$boolOr->addShould($queryString);
}

/**
* @param $query
*/
private function prepareQueryStringWithFuzzy($query)
private function prepareQueryStringWithFuzzy($query, &$boolOr)
{
list($attributes, $keyword, $defaultOperator, $prefixLength) = array_pad($query, 4, null);

Expand All @@ -631,8 +632,7 @@ private function prepareQueryStringWithFuzzy($query)
->setDefaultOperator($defaultOperator)
->setFuzzyPrefixLength($prefixLength)
;

$this->filter->addFilter($queryString);
$boolOr->addShould($queryString);
}

/**
Expand Down

0 comments on commit 557f5a9

Please sign in to comment.