Skip to content

Commit

Permalink
Add support for allow_seen in Recommendation requests
Browse files Browse the repository at this point in the history
  • Loading branch information
foglcz committed Sep 18, 2018
1 parent a30131d commit 5d8b09f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

## Unreleased

### Added
- `UserRecommendation` has new method `setAllowSeen(true|false)`, which allows recommending of already visited items.

## 2.0.0 - 2018-09-04
See [UPGRADE-2.0.md](UPGRADE-2.0.md) for upgrade instructions.

Expand Down
20 changes: 20 additions & 0 deletions src/Model/Command/UserRecommendation.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class UserRecommendation extends AbstractCommand implements UserAwareInterface
private $modelName;
/** @var string[] */
private $responseProperties = [];
/** @var bool */
private $allowSeen = false;

private function __construct(
string $userId,
Expand Down Expand Up @@ -173,6 +175,20 @@ public function setModelName(string $modelName): self
return $this;
}

/**
* Allow items, that the user has already "seen"
*
* By default user won't see any items, that it has visitted (and we have recorded DetailView interaction.)
* If you want to circumvent this, and get recommendations including the ones, that the user has already visitted,
* you can set the "seen" allowance here.
*/
public function setAllowSeen(bool $seen): self
{
$this->allowSeen = $seen;

return $this;
}

public function getUserId(): string
{
return $this->userId;
Expand Down Expand Up @@ -242,6 +258,10 @@ protected function getCommandParameters(): array
$parameters['model_name'] = $this->modelName;
}

if ($this->allowSeen !== false) {
$parameters['allow_seen'] = $this->allowSeen;
}

return $parameters;
}
}
5 changes: 4 additions & 1 deletion tests/unit/Model/Command/UserRecommendationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function shouldBeInstantiableViaNamedConstructorWithDefaultValues(): void
'filter_type' => UserRecommendation::FILTER_TYPE_MQL,
'properties' => [],
// when using default model name, parameter "model_name" should be absent.
// by default, allow_seen is absent
],
],
$command->jsonSerialize()
Expand All @@ -50,7 +51,8 @@ public function shouldUseCustomParameters(): void
$command->setMinimalRelevance(MinimalRelevance::HIGH())
->enableHardRotation()
->setFilters(['foo = bar', 'baz = ban'])
->setModelName($modelName);
->setModelName($modelName)
->setAllowSeen(true);

$this->assertInstanceOf(UserRecommendation::class, $command);
$this->assertSame(
Expand All @@ -68,6 +70,7 @@ public function shouldUseCustomParameters(): void
'filter_type' => UserRecommendation::FILTER_TYPE_MQL,
'properties' => [],
'model_name' => $modelName,
'allow_seen' => true,
],
],
$command->jsonSerialize()
Expand Down

0 comments on commit 5d8b09f

Please sign in to comment.