Skip to content

Commit

Permalink
#37 Removes the weightedsearch key from the initial data array so tha…
Browse files Browse the repository at this point in the history
…t getWeightedSearch() can load its value from the config if it isn't set yet
  • Loading branch information
extracts committed Nov 29, 2023
1 parent f6d7469 commit ad067cb
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
* @method $this setFacet( Set $facet )
* @method $this addFields( string $fields )
* @method $this addSort( $sorting )
* @method $this setWeightedSearch( bool $isWeightedSearch )
* @method $this setWeightedFields( int[] $weightedFields ) assigns boost factors to fields (e.g. [ 'title' => 10, 'abstract' => 0.5 ])
*/
class Query
Expand All @@ -108,7 +107,6 @@ public function reset()
'filter' => null,
'facet' => null,
'subfilters' => null,
'weightedsearch' => null, // first getWeightedSearch() call will set this to true or false
'weightedfields' => null,
];
}
Expand Down Expand Up @@ -198,7 +196,7 @@ protected function normalizeDirection($ascending)
*/
public function getWeightedSearch()
{
if ($this->data['weightedsearch'] === null) {
if (! isset($this->data['weightedsearch'])) {
$config = Config::get();

if (isset($config->search->weightedSearch)) {
Expand All @@ -211,6 +209,17 @@ public function getWeightedSearch()
return $this->data['weightedsearch'];
}

/**
* Set to true if a weighted search shall be used, otherwise set to false.
*
* @param bool $value
* @return $this fluent interface
*/
public function setWeightedSearch($value)
{
$this->data['weightedsearch'] = ! ! $value;
}

/**
* Returns boost factors keyed by field (e.g. [ 'title' => 10, 'abstract' => 0.5 ]).
*
Expand Down Expand Up @@ -314,7 +323,6 @@ public function set($name, $value, $adding = false)
break;

case 'union':
case 'weightedsearch':
if ($adding) {
throw new InvalidArgumentException('invalid parameter access on ' . $name);
}
Expand Down

0 comments on commit ad067cb

Please sign in to comment.