From: Vincent Vanwaelscappel Date: Tue, 19 Oct 2021 16:13:12 +0000 (+0200) Subject: wip #4808 @0.25 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=fd55f5ff03b63669c44cd7ded632c8164a795fdd;p=cubist_minisearch.git wip #4808 @0.25 --- diff --git a/composer.json b/composer.json index 19df3d7..6a00b60 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,8 @@ ], "require": { "php": ">=7.3.0", - "laravel/framework": "9.x-dev" - + "laravel/framework": "9.x-dev", + "ext-json": "*" }, "repositories": [ { diff --git a/src/Document.php b/src/Document.php index 9262646..07dee91 100644 --- a/src/Document.php +++ b/src/Document.php @@ -4,5 +4,140 @@ namespace Cubist\Minisearch; class Document { + /** + * @var string + */ + protected $id; + + /** + * @var string + */ + protected $url; + + /** + * @var string + */ + protected $title; + + /** + * @var string + */ + protected $text; + + /** + * @var string + */ + protected $thumb; + + /** + * @var string + */ + protected $type; + + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @return string + */ + public function getText(): string + { + return $this->text; + } + + /** + * @return string + */ + public function getThumb(): string + { + return $this->thumb; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $id + */ + public function setId(string $id): void + { + $this->id = $id; + } + + /** + * @param string $text + */ + public function setText(string $text): void + { + $this->text = $text; + } + + /** + * @param string $thumb + */ + public function setThumb(string $thumb): void + { + $this->thumb = $thumb; + } + + /** + * @param string $title + */ + public function setTitle(string $title): void + { + $this->title = $title; + } + + /** + * @param string $type + */ + public function setType(string $type): void + { + $this->type = $type; + } + + /** + * @param string $url + */ + public function setUrl(string $url): void + { + $this->url = $url; + } + + /** + * @return array + */ + public function asArray() + { + //TODO + return []; + } } \ No newline at end of file diff --git a/src/Index.php b/src/Index.php index a5812ff..06cc8b8 100644 --- a/src/Index.php +++ b/src/Index.php @@ -2,7 +2,69 @@ namespace Cubist\Minisearch; -class Index +use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldBeUnique; +use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Foundation\Bus\Dispatchable; +use Illuminate\Queue\InteractsWithQueue; +use Illuminate\Queue\SerializesModels; + +class Index implements ShouldQueue, ShouldBeUnique { + use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + + /** @var Document[] */ + protected $documents = []; + + /** + * @var string + */ + protected $output; + + /** + * @param $document Document + */ + public function addDocument($document) + { + $this->documents[$document->getId()] = $document; + } + + /** + * @param $id + * @return Document|null + */ + public function getDocumentById($id) + { + return $this->documents[$id] ?? null; + } + + /** + * @param string $output + */ + public function setOutput(string $output): void + { + $this->output = $output; + } + + /** + * @return string + */ + public function getOutput(): string + { + return $this->output; + } + + public function handle() + { + file_put_contents($this->generateCode(), $this->getOutput()); + } + public function generateCode() + { + $res = []; + foreach ($this->documents as $document) { + $res[] = $document->asArray(); + } + return 'const documents = ' . json_encode($res) . ';'; + } } \ No newline at end of file