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
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