Description
Hi everyone ๐๐ป
It seems that the latest version of the bundle does not allows to load data into documents when using it in symfony/demo
project.
Environment:
- OS: macOS
- PHP: 7.4
- MeiliSearch version: latest
- MeiliSearch PHP SDK: 0.16.0
- meilisearch-symfony version: 0.2.6
Expected behavior
The data should be loaded in documents along with indices.
Current behavior
Current configuration:
meili_search:
indices:
- name: posts
class: App\Entity\Post
enable_serializer_groups: true
Current entity configuration:
/**
* @var int
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Groups({"searchable"})
*/
private $id;
/**
* @var string
*
* @ORM\Column(type="string")
* @Assert\NotBlank
*
* @Groups({"searchable"})
*/
private $title;
/**
* @var string
*
* @ORM\Column(type="string")
*
* @Groups({"searchable"})
*/
private $slug;
/**
* @var string
*
* @ORM\Column(type="string")
* @Assert\NotBlank(message="post.blank_summary")
* @Assert\Length(max=255)
*
* @Groups({"searchable"})
*/
private $summary;
/**
* @var string
*
* @ORM\Column(type="text")
* @Assert\NotBlank(message="post.blank_content")
* @Assert\Length(min=10, minMessage="post.too_short_content")
*
* @Groups({"searchable"})
*/
private $content;
When launching php bin/console meili:import
, here's the error displayed:
In MeiliSearchImportCommand.php line 195:
Notice: Undefined index: number
meili:import [-i|--indices [INDICES]] [--update-settings]
Screenshots or Logs
Current logs (in Symfony):
doctrine.DEBUG: SELECT t0.id AS id_1, t0.title AS title_2, t0.slug AS slug_3, t0.summary AS summary_4, t0.content AS content_5, t0.published_at AS published_at_6, t0.author_id AS author_id_7 FROM symfony_demo_post t0 LIMIT 500 [] []
console.CRITICAL: Error thrown while running command "meili:import". Message: "Notice: Undefined index: number" {"exception":"[object] (ErrorException(code: 0): Notice: Undefined index: number at /__PROJECT__/vendor/meilisearch/search-bundle/src/Command/MeiliSearchImportCommand.php:195)","command":"meili:import","message":"Notice: Undefined index: number"} []
console.DEBUG: Command "meili:import" exited with code "1" {"command":"meili:import","code":1} []
Current logs (in Meilisearch):
[__DATE__ INFO actix_web::middleware::logger] 127.0.0.1:54907 "GET /indexes/dev_posts HTTP/1.1" 200 146 "-" "Symfony HttpClient/Curl" 0.000302
[__DATE__ INFO actix_web::middleware::logger] 127.0.0.1:54907 "POST /indexes/dev_posts/documents HTTP/1.1" 202 14 "-" "Symfony HttpClient/Curl" 0.004908
[__DATE__ INFO actix_web::middleware::logger] 127.0.0.1:54907 "GET /indexes/dev_posts/updates/9 HTTP/1.1" 200 167 "-" "Symfony HttpClient/Curl" 0.000269
[__DATE__ INFO actix_web::middleware::logger] 127.0.0.1:54907 "GET /indexes/dev_posts/updates/9 HTTP/1.1" 200 167 "-" "Symfony HttpClient/Curl" 0.000509
[__DATE__ INFO meilisearch_lib::index::updates] document addition done: DocumentAdditionResult { nb_documents: 30 }
Here's a dump()
when debugging the call $indexInstance->getUpdateStatus($apiResponse['updateId']);
in MeiliSearchImportCommand
at line 195
:
array:5 [
"status" => "processing"
"updateId" => 8
"type" => array:1 [
"name" => "DocumentsAddition"
]
"enqueuedAt" => "__DATE__"
"startedProcessingAt" => "__DATE__"
]
It seems that when calling $formattedResponse[$indexName] += $updateStatus['type']['number'];
, the number
key is not available as type
does not contains it.
I'm not sure about the internal usage of number
(maybe displaying the number of row loaded), it seems that when MS is processing, the number
key is not returned ๐ค
Possible solution:
It seems that by default Indexes
does not wait until the operation is processed
:
public function waitForPendingUpdate($updateId, $timeoutInMs = 5000, $intervalInMs = 50): array
{
$timeout_temp = 0;
while ($timeoutInMs > $timeout_temp) {
$res = $this->getUpdateStatus($updateId);
if ('enqueued' != $res['status']) {
return $res;
}
$timeout_temp += $intervalInMs;
usleep(1000 * $intervalInMs);
}
throw new TimeOutException();
}
Here's what can be used:
public function waitForPendingUpdate($updateId, $timeoutInMs = 5000, $intervalInMs = 50): array
{
$timeout_temp = 0;
while ($timeoutInMs > $timeout_temp) {
$res = $this->getUpdateStatus($updateId);
if ('processed' === $res['status']) {
return $res;
}
$timeout_temp += $intervalInMs;
usleep(1000 * $intervalInMs);
}
throw new TimeOutException();
}
By waiting for updates to be processed
, here's the output:
Indexed 30 / 30 App\Entity\Post entities into dev_posts index
Done!
I don't know if it helps but the fix seems to be relatively small.
Thanks again for the feedback and have a great day ๐