Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add faceting and pagination settings #362

Merged
merged 4 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/Endpoints/Delegates/HandlesSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,40 @@ public function resetDisplayedAttributes(): array
return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/displayed-attributes');
}

// Settings - Faceting

public function getFaceting(): array
{
return $this->http->get(self::PATH.'/'.$this->uid.'/settings/faceting');
}

public function updateFaceting(array $faceting): array
{
return $this->http->patch(self::PATH.'/'.$this->uid.'/settings/faceting', $faceting);
}

public function resetFaceting(): array
{
return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/faceting');
}

// Settings - Pagination

public function getPagination(): array
{
return $this->http->get(self::PATH.'/'.$this->uid.'/settings/pagination');
}

public function updatePagination(array $pagination): array
{
return $this->http->patch(self::PATH.'/'.$this->uid.'/settings/pagination', $pagination);
}

public function resetPagination(): array
{
return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/pagination');
}

// Settings - Stop-words

public function getStopWords(): array
Expand Down
41 changes: 23 additions & 18 deletions tests/Endpoints/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,29 @@ protected function setUp(): void
$this->index = $this->createEmptyIndex('index');
}

public function testIndexSettingsAlwaysReturnArrays(): void
public function testIndexGetSettings(): void
{
/* @phpstan-ignore-next-line */
$this->assertIsArray($this->index->getSynonyms());
/* @phpstan-ignore-next-line */
$this->assertIsArray($this->index->getStopWords());
/* @phpstan-ignore-next-line */
$this->assertIsArray($this->index->getSortableAttributes());
/* @phpstan-ignore-next-line */
$this->assertIsArray($this->index->getSearchableAttributes());
/* @phpstan-ignore-next-line */
$this->assertIsArray($this->index->getRankingRules());
/* @phpstan-ignore-next-line */
$this->assertIsArray($this->index->getFilterableAttributes());
/* @phpstan-ignore-next-line */
$this->assertIsArray($this->index->getDisplayedAttributes());
/* @phpstan-ignore-next-line */
$this->assertIsArray($this->index->getTypoTolerance());
$this->assertSame([], $this->index->getSynonyms());
$this->assertSame([], $this->index->getStopWords());
$this->assertSame([], $this->index->getSortableAttributes());
$this->assertSame(['*'], $this->index->getSearchableAttributes());
$this->assertSame(
['words', 'typo', 'proximity', 'attribute', 'sort', 'exactness'],
$this->index->getRankingRules()
);
$this->assertSame([], $this->index->getFilterableAttributes());
$this->assertSame(['*'], $this->index->getDisplayedAttributes());
$this->assertSame(['maxValuesPerFacet' => 100], $this->index->getFaceting());
$this->assertSame(['maxTotalHits' => 1000], $this->index->getPagination());
$this->assertSame(
[
'enabled' => true,
'minWordSizeForTypos' => ['oneTypo' => 5, 'twoTypos' => 9],
'disableOnWords' => [],
'disableOnAttributes' => [],
],
$this->index->getTypoTolerance(),
);
}

public function testGetPrimaryKey(): void
Expand Down Expand Up @@ -95,7 +100,7 @@ public function testGetUpdatedAtString(): void
$this->assertSame($rawInfo['updatedAt'], $this->index->getUpdatedAtString());
}

public function testfetchRawInfo(): void
public function testFetchRawInfo(): void
{
$index = $this->createEmptyIndex(
'indexB',
Expand Down