13 - Add language_confidence column and Page model cast
This commit is contained in:
parent
cda1414cd8
commit
a37b1da145
3 changed files with 23 additions and 0 deletions
|
|
@ -25,6 +25,7 @@ class Page extends Model
|
||||||
'url',
|
'url',
|
||||||
'status',
|
'status',
|
||||||
'language',
|
'language',
|
||||||
|
'language_confidence',
|
||||||
'title',
|
'title',
|
||||||
'instance_id',
|
'instance_id',
|
||||||
'posted_at',
|
'posted_at',
|
||||||
|
|
@ -34,6 +35,7 @@ class Page extends Model
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'status' => PageStatusEnum::class,
|
'status' => PageStatusEnum::class,
|
||||||
|
'language_confidence' => 'float',
|
||||||
'posted_at' => 'datetime',
|
'posted_at' => 'datetime',
|
||||||
'fetched_at' => 'datetime',
|
'fetched_at' => 'datetime',
|
||||||
'failed_at' => 'datetime',
|
'failed_at' => 'datetime',
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ public function up(): void
|
||||||
$table->text('url')->unique();
|
$table->text('url')->unique();
|
||||||
$table->string('status')->default(PageStatusEnum::Discovered->value)->index();
|
$table->string('status')->default(PageStatusEnum::Discovered->value)->index();
|
||||||
$table->string('language', 35)->nullable()->index();
|
$table->string('language', 35)->nullable()->index();
|
||||||
|
$table->decimal('language_confidence', 4, 3)->nullable();
|
||||||
$table->string('title')->nullable();
|
$table->string('title')->nullable();
|
||||||
$table->foreignId('instance_id')
|
$table->foreignId('instance_id')
|
||||||
->nullable()
|
->nullable()
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,26 @@ public function test_page_latest_crawl_returns_row_with_latest_created_at(): voi
|
||||||
$this->assertSame('sentinel-latest', $latest->error_message);
|
$this->assertSame('sentinel-latest', $latest->error_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_language_confidence_is_fillable_nullable_and_cast_to_float(): void
|
||||||
|
{
|
||||||
|
// Column must exist, be nullable (null round-trips cleanly), be mass-assignable,
|
||||||
|
// and the 'float' cast must be applied so we get a PHP float back, not a string.
|
||||||
|
$withConfidence = Page::factory()->createQuietly([
|
||||||
|
'language' => 'en',
|
||||||
|
'language_confidence' => 0.857,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$fresh = $withConfidence->fresh();
|
||||||
|
|
||||||
|
$this->assertNotNull($fresh);
|
||||||
|
$this->assertIsFloat($fresh->language_confidence);
|
||||||
|
$this->assertEqualsWithDelta(0.857, $fresh->language_confidence, 0.001);
|
||||||
|
|
||||||
|
$withoutConfidence = Page::factory()->createQuietly();
|
||||||
|
|
||||||
|
$this->assertNull($withoutConfidence->fresh()->language_confidence);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_page_status_is_cast_to_enum(): void
|
public function test_page_status_is_cast_to_enum(): void
|
||||||
{
|
{
|
||||||
$cases = [
|
$cases = [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue