function = $function ?? new \Spameri\ElasticQuery\FunctionScore\FunctionScoreCollection(); } public function function(): \Spameri\ElasticQuery\FunctionScore\FunctionScoreCollection { return $this->function; } public function scoreMode(): string|null { return $this->scoreMode; } /** * @param array $queryPart * @return array> */ public function toArray(array $queryPart): array { $functions = []; foreach ($this->function() as $function) { $functions[] = $function->toArray(); } $array = [ 'function_score' => [ 'query' => $queryPart, 'functions' => $functions, ], ]; if ($this->scoreMode !== null) { $array['function_score']['score_mode'] = $this->scoreMode; } if ($this->boostMode !== null) { $array['function_score']['boost_mode'] = $this->boostMode; } if ($this->boost !== null) { $array['function_score']['boost'] = $this->boost; } if ($this->maxBoost !== null) { $array['function_score']['max_boost'] = $this->maxBoost; } if ($this->minScore !== null) { $array['function_score']['min_score'] = $this->minScore; } return $array; } }