Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Merge 2d06768 into 496d468
Browse files Browse the repository at this point in the history
  • Loading branch information
TurboModule committed Nov 20, 2019
2 parents 496d468 + 2d06768 commit 7863828
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/AzureSearch/Index.php
Expand Up @@ -5,6 +5,7 @@

use BenjaminHirsch\Azure\Search\Index\Field;
use BenjaminHirsch\Azure\Search\Index\Suggest;
use BenjaminHirsch\Azure\Search\Index\ScoringProfile;

final class Index
{
Expand Down Expand Up @@ -47,6 +48,11 @@ final class Index
*/
private $suggesters = [];

/**
* @var array
*/
private $scoringProfiles = [];

/**
* @var mixed
*/
Expand Down Expand Up @@ -119,13 +125,14 @@ public function addCrossOrigins($allowedOrigins, int $maxAgeInSeconds = 0): Inde
}

/**
* @todo Implement possibility to add scoring profiles
*
* @throws \Exception
* @param ScoringProfile $scoringProfile
* @return Index
*/
public function addScoringProfile()
public function addScoringProfile(ScoringProfile $scoringProfile)
{
throw new \RuntimeException('Not yet implemented');
$this->scoringProfiles[] = $scoringProfile();

return $this;
}

/**
Expand All @@ -137,7 +144,8 @@ public function __invoke()
'name' => $this->name,
'fields' => $this->fields,
'suggesters' => $this->suggesters,
'corsOptions' => $this->crossOrigins
'corsOptions' => $this->crossOrigins,
'scoringProfiles' => $this->scoringProfiles
];
}
}
39 changes: 39 additions & 0 deletions src/AzureSearch/Index/ScoringProfile.php
@@ -0,0 +1,39 @@
<?php

namespace BenjaminHirsch\Azure\Search\Index;

final class ScoringProfile
{
/**
* @var string
*/
private $name;

/**
* @var array
*/
private $options = [];

public function __construct(string $name, array $options)
{
$this->name = $name;
$this->options = $options;
}

/**
* @return array
*/
public function __invoke()
{
$data = ["name" => $this->name];

foreach ($this->options as $key => $value) {
if ($key === "weights") {
$data["text"] = [$key => $value];
} else {
$data[$key] = $value;
}
}
return $data;
}
}

0 comments on commit 7863828

Please sign in to comment.