]> _ Git - cubist_minisearch.git/commitdiff
wip #4808 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 19 Oct 2021 16:13:12 +0000 (18:13 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 19 Oct 2021 16:13:12 +0000 (18:13 +0200)
composer.json
src/Document.php
src/Index.php

index 19df3d7313422dae68afa9334b4f62493d99c7a0..6a00b6031c130c333f2b0004845cb49987bb70ed 100644 (file)
@@ -21,8 +21,8 @@
   ],
   "require": {
     "php": ">=7.3.0",
-    "laravel/framework": "9.x-dev"
-
+    "laravel/framework": "9.x-dev",
+    "ext-json": "*"
   },
   "repositories": [
     {
index 926264641d35fd8896d181b07f5001e40d3a3561..07dee91df39ab73d628351f2c15395551de58a94 100644 (file)
@@ -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
index a5812ffc6b04a2a6f8fb6df2214c53b34df2d637..06cc8b84f239a0c5a3d21e545508472f8d3c80b7 100644 (file)
@@ -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