From ad067cb55d64f575e00a511d723f1fc9d8ec36af Mon Sep 17 00:00:00 2001 From: Matthias Steffens Date: Wed, 29 Nov 2023 16:14:13 +0100 Subject: [PATCH] #37 Removes the weightedsearch key from the initial data array so that getWeightedSearch() can load its value from the config if it isn't set yet --- src/Query.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Query.php b/src/Query.php index 64285ac..24f4f4e 100644 --- a/src/Query.php +++ b/src/Query.php @@ -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 @@ -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, ]; } @@ -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)) { @@ -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 ]). * @@ -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); }