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

Changes related to the next Meilisearch release (v1.12.0) #692

Merged
merged 37 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
505cc43
Update README.md
meili-bot Nov 26, 2024
ff24520
Merge branch 'main' into bump-meilisearch-v0.12.0
curquiza Dec 3, 2024
8770e2e
Add setReverse on TasksQuery
Strift Dec 4, 2024
7d529b9
Add parameter to get tasks in reverse order
Strift Dec 4, 2024
4458e21
Run lint:fix
Strift Dec 4, 2024
250dd47
Fix tests
Strift Dec 4, 2024
8adf445
Update tests/Contracts/TasksQueryTest.php
Strift Dec 4, 2024
4bbf82d
Replace json_encode usage
Strift Dec 4, 2024
44f2671
Make date in test immutable
Strift Dec 4, 2024
23feaa4
Run composer lint:fix
Strift Dec 4, 2024
3110968
Add method to retrieve all batches
Strift Dec 4, 2024
3783e04
Add tests for fetching batches
Strift Dec 4, 2024
02c8e81
Add tests for getBatch()
Strift Dec 4, 2024
f1ca121
Run lint:fix
Strift Dec 4, 2024
6504e83
Add filtering by batchUid for getTasks
Strift Dec 4, 2024
0ab1764
Rename test
Strift Dec 4, 2024
2e409e3
Run lint:fix
Strift Dec 4, 2024
aab82ed
Update tests based on PHPstan feedback
Strift Dec 4, 2024
1cd2719
Update src/Endpoints/Delegates/HandlesBatches.php
Strift Dec 5, 2024
94ed604
Remove missing results check
Strift Dec 5, 2024
05c441c
Add todo to refactor tests to cleanup
Strift Dec 5, 2024
77cd241
Merge pull request #698 from meilisearch/feat/add-tasks-reverse
Strift Dec 5, 2024
689c6f1
Merge branch 'bump-meilisearch-v0.12.0' into feat/add-batches-endpoints
Strift Dec 5, 2024
1e46dae
Run lint:fix
Strift Dec 5, 2024
a86501f
Update tests for get/update/reset settings
Strift Dec 5, 2024
a321f2d
Add get/update/reset methods for facet search settings
Strift Dec 5, 2024
bca1157
Add get/update/reset methods for prefix search settings
Strift Dec 5, 2024
76df31b
Add Meilisearch version requirement in documentation
Strift Dec 5, 2024
9e22f04
Run lint:fix
Strift Dec 5, 2024
a05224a
Update assertion
Strift Dec 5, 2024
3e0a026
Merge pull request #702 from meilisearch/feat/add-v1.12-settings
Strift Dec 6, 2024
8254856
Merge pull request #699 from meilisearch/feat/add-batches-endpoints
Strift Dec 6, 2024
8d6c5f7
Merge branch 'main' into bump-meilisearch-v0.12.0
Strift Dec 12, 2024
18ee34b
Merge branch 'main' into bump-meilisearch-v0.12.0
curquiza Dec 12, 2024
f5f9a4f
Add batch progress (#709)
Strift Dec 19, 2024
1e5ac8e
Add 1.12 code samples (#711)
Strift Dec 19, 2024
69ad2ed
Merge branch 'main' into bump-meilisearch-v0.12.0
curquiza Dec 23, 2024
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
18 changes: 17 additions & 1 deletion .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ update_displayed_attributes_1: |-
]);
reset_displayed_attributes_1: |-
$client->index('movies')->resetDisplayedAttributes();
get_typo_tolerance_1:
get_typo_tolerance_1: |-
$client->index('books')->getTypoTolerance();
update_typo_tolerance_1: |-
$client->index('books')->updateTypoTolerance([
Expand Down Expand Up @@ -775,3 +775,19 @@ update_localized_attribute_settings_1: |-
]);
reset_localized_attribute_settings_1: |-
$client->index('INDEX_NAME')->resetLocalizedAttributes();
get_facet_search_settings_1: |-
$client->index('INDEX_NAME')->getFacetSearch();
update_facet_search_settings_1: |-
$client->index('INDEX_NAME')->updateFacetSearch(false);
reset_facet_search_settings_1: |-
$client->index('INDEX_NAME')->resetFacetSearch();
get_prefix_search_settings_1: |-
$client->index('INDEX_NAME')->getPrefixSearch();
update_prefix_search_settings_1: |-
$client->index('INDEX_NAME')->updatePrefixSearch('disabled');
reset_prefix_search_settings_1: |-
$client->index('INDEX_NAME')->resetPrefixSearch();
get_all_batches_1: |-
$client->getBatches();
get_batch_1: |-
$client->getBatch(BATCH_UID);
4 changes: 4 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Meilisearch;

use Meilisearch\Endpoints\Batches;
use Meilisearch\Endpoints\Delegates\HandlesBatches;
use Meilisearch\Endpoints\Delegates\HandlesDumps;
use Meilisearch\Endpoints\Delegates\HandlesIndex;
use Meilisearch\Endpoints\Delegates\HandlesKeys;
Expand Down Expand Up @@ -34,6 +36,7 @@ class Client
use HandlesSnapshots;
use HandlesSystem;
use HandlesMultiSearch;
use HandlesBatches;

/**
* @param array<int, string> $clientAgents
Expand All @@ -52,6 +55,7 @@ public function __construct(
$this->version = new Version($this->http);
$this->stats = new Stats($this->http);
$this->tasks = new Tasks($this->http);
$this->batches = new Batches($this->http);
$this->keys = new Keys($this->http);
$this->dumps = new Dumps($this->http);
$this->snapshots = new Snapshots($this->http);
Expand Down
68 changes: 68 additions & 0 deletions src/Contracts/BatchesQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

namespace Meilisearch\Contracts;

use Meilisearch\Endpoints\Delegates\TasksQueryTrait;

class BatchesQuery
{
use TasksQueryTrait;

private ?int $from = null;

/**
* @var non-negative-int|null
*/
private ?int $limit = null;

private ?bool $reverse = null;

/**
* @return $this
*/
public function setFrom(int $from): self
{
$this->from = $from;

return $this;
}

/**
* @return $this
*/
public function setLimit(int $limit): self
{
$this->limit = $limit;

return $this;
}

/**
* @return $this
*/
public function setReverse(bool $reverse): self
{
$this->reverse = $reverse;

return $this;
}

public function toArray(): array
{
return array_filter(
array_merge(
$this->baseArray(),
[
'from' => $this->from,
'limit' => $this->limit,
'reverse' => (null !== $this->reverse ? ($this->reverse ? 'true' : 'false') : null),
]
),
static function ($item) {
return null !== $item;
}
);
}
}
94 changes: 94 additions & 0 deletions src/Contracts/BatchesResults.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

declare(strict_types=1);

namespace Meilisearch\Contracts;

class BatchesResults extends Data
{
/**
* @var non-negative-int
*/
private int $next;

/**
* @var non-negative-int
*/
private int $limit;

/**
* @var non-negative-int
*/
private int $from;

/**
* @var non-negative-int
*/
private int $total;

public function __construct(array $params)
{
parent::__construct($params['results']);

$this->from = $params['from'] ?? 0;
$this->limit = $params['limit'] ?? 0;
$this->next = $params['next'] ?? 0;
$this->total = $params['total'] ?? 0;
}

/**
* @return array<int, array>
*/
public function getResults(): array
{
return $this->data;
}

/**
* @return non-negative-int
*/
public function getNext(): int
{
return $this->next;
}

/**
* @return non-negative-int
*/
public function getLimit(): int
{
return $this->limit;
}

/**
* @return non-negative-int
*/
public function getFrom(): int
{
return $this->from;
}

/**
* @return non-negative-int
*/
public function getTotal(): int
{
return $this->total;
}

public function toArray(): array
{
return [
'results' => $this->data,
'next' => $this->next,
'limit' => $this->limit,
'from' => $this->from,
'total' => $this->total,
];
}

public function count(): int
{
return \count($this->data);
}
}
28 changes: 27 additions & 1 deletion src/Contracts/TasksQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class TasksQuery
*/
private ?array $canceledBy = null;

private ?int $batchUid = null;

private ?bool $reverse = null;

/**
* @return $this
*/
Expand Down Expand Up @@ -54,6 +58,23 @@ public function setLimit(int $limit): self
return $this;
}

/**
* @return $this
*/
public function setBatchUid(int $batchUid): self
{
$this->batchUid = $batchUid;

return $this;
}

public function setReverse(bool $reverse): self
{
$this->reverse = $reverse;

return $this;
}

public function toArray(): array
{
return array_filter(
Expand All @@ -63,8 +84,13 @@ public function toArray(): array
'from' => $this->from,
'limit' => $this->limit,
'canceledBy' => $this->formatArray($this->canceledBy),
'batchUid' => $this->batchUid,
'reverse' => (null !== $this->reverse ? ($this->reverse ? 'true' : 'false') : null),
]
), static function ($item) { return null !== $item; }
),
static function ($item) {
return null !== $item;
}
);
}
}
22 changes: 22 additions & 0 deletions src/Endpoints/Batches.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Meilisearch\Endpoints;

use Meilisearch\Contracts\Endpoint;

class Batches extends Endpoint
{
protected const PATH = '/batches';

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

public function all(array $query = []): array
{
return $this->http->get(self::PATH.'/', $query);
}
}
28 changes: 28 additions & 0 deletions src/Endpoints/Delegates/HandlesBatches.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Meilisearch\Endpoints\Delegates;

use Meilisearch\Contracts\BatchesQuery;
use Meilisearch\Contracts\BatchesResults;
use Meilisearch\Endpoints\Batches;

trait HandlesBatches
{
protected Batches $batches;

public function getBatch($uid): array
{
return $this->batches->get($uid);
}

public function getBatches(?BatchesQuery $options = null): BatchesResults
{
$query = null !== $options ? $options->toArray() : [];

$response = $this->batches->all($query);

return new BatchesResults($response);
}
}
56 changes: 56 additions & 0 deletions src/Endpoints/Delegates/HandlesSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,60 @@ public function resetEmbedders(): array
{
return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/embedders');
}

// Settings - Facet Search

/**
* @since Meilisearch v1.12.0
*/
public function getFacetSearch(): bool
{
return $this->http->get(self::PATH.'/'.$this->uid.'/settings/facet-search');
}

/**
* @since Meilisearch v1.12.0
*/
public function updateFacetSearch(bool $facetSearch): array
{
return $this->http->put(self::PATH.'/'.$this->uid.'/settings/facet-search', $facetSearch);
}

/**
* @since Meilisearch v1.12.0
*/
public function resetFacetSearch(): array
{
return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/facet-search');
}

// Settings - Prefix Search

/**
* @return 'indexingTime'|'disabled'
*
* @since Meilisearch v1.12.0
*/
public function getPrefixSearch(): string
{
return $this->http->get(self::PATH.'/'.$this->uid.'/settings/prefix-search');
}

/**
* @param 'indexingTime'|'disabled' $prefixSearch
*
* @since Meilisearch v1.12.0
*/
public function updatePrefixSearch(string $prefixSearch): array
{
return $this->http->put(self::PATH.'/'.$this->uid.'/settings/prefix-search', $prefixSearch);
}

/**
* @since Meilisearch v1.12.0
*/
public function resetPrefixSearch(): array
{
return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/prefix-search');
}
}
Loading
Loading