Skip to content

Commit

Permalink
sibling tags
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Apr 15, 2024
1 parent 252d09f commit 52827ad
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Modules/TagFunction/app/Contracts/TaggableContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public function tags(): MorphToMany;

public function addTag(string $tag): void;

public function siblingTags() : array;
public function siblingTags(): array;
}
15 changes: 7 additions & 8 deletions Modules/TagFunction/tests/Feature/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,23 @@ public function test_sibling_tags()
$document = Document::factory()->create();

$documentChunk = DocumentChunk::factory()->create([
'document_id' => $document->id
'document_id' => $document->id,
]);
$documentChunk->addTag("foobar1");

$documentChunk->addTag('foobar1');

$documentChunk = DocumentChunk::factory()->create([
'document_id' => $document->id
'document_id' => $document->id,
]);

$this->assertCount(2, $document->refresh()->document_chunks);
$documentChunk->addTag("foobar1");
$documentChunk->addTag("foobar2");
$documentChunk->addTag('foobar1');
$documentChunk->addTag('foobar2');

$tags = $document->siblingTags();

$this->assertCount(2, $tags);

$this->assertTrue(in_array("foobar1", $document->siblingTags()));
$this->assertTrue(in_array('foobar1', $document->siblingTags()));
}

}
1 change: 0 additions & 1 deletion app/Domains/Documents/Transformers/PdfTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Domains\Collections\CollectionStatusEnum;
use App\Events\CollectionStatusEvent;
use App\Jobs\DocumentProcessingCompleteJob;
use App\Jobs\SummarizeDataJob;
use App\Jobs\SummarizeDocumentJob;
use App\Jobs\VectorlizeDataJob;
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/ProcessFileJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function handle(): void
new ParsePdfFileJob($this->document),
])
->name('Process PDF Document - '.$document->id)
->finally(function (Batch $batch) use ($document) {
->finally(function (Batch $batch) {
})
->allowFailures()
->dispatch();
Expand Down
3 changes: 2 additions & 1 deletion app/Models/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public function getDriver(): string
return $this->driver->value;
}

public function siblingTags() : array {
public function siblingTags(): array
{
return [];
}

Expand Down
21 changes: 11 additions & 10 deletions app/Models/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ class Document extends Model implements HasDrivers, TaggableContract
'summary_status' => StatusEnum::class,
];

public function siblingTags() : array {
public function siblingTags(): array
{
return Tag::query()
->select("tags.name")
->join("taggables", "taggables.tag_id", "=", "tags.id")
->join("document_chunks", "document_chunks.document_id", "=", "taggables.taggable_id")
->where("taggables.taggable_type", "=", DocumentChunk::class)
->where("document_chunks.document_id", "=", $this->id)
->distinct('name')
->get()
->pluck("name")
->toArray();
->select('tags.name')
->join('taggables', 'taggables.tag_id', '=', 'tags.id')
->join('document_chunks', 'document_chunks.document_id', '=', 'taggables.taggable_id')
->where('taggables.taggable_type', '=', DocumentChunk::class)
->where('document_chunks.document_id', '=', $this->id)
->distinct('name')
->get()
->pluck('name')
->toArray();
}

public function collection(): BelongsTo
Expand Down
4 changes: 2 additions & 2 deletions app/Models/DocumentChunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public function document()
return $this->belongsTo(Document::class);
}

public function siblingTags() : array {
public function siblingTags(): array
{
return [];
}


/**
* The "booted" method of the model.
*
Expand Down
3 changes: 0 additions & 3 deletions tests/Feature/Models/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tests\Feature\Models;

use LlmLaraHub\TagFunction\Models\Tag;
use Tests\TestCase;

class DocumentTest extends TestCase
Expand All @@ -19,6 +18,4 @@ public function test_factory(): void
$this->assertCount(1, $model->collection->documents);
$this->assertNotNull($model->collection->documents()->first()->id);
}


}

0 comments on commit 52827ad

Please sign in to comment.