search index

This commit is contained in:
2023-10-22 16:09:36 +03:00
parent 1a6de5c1bb
commit e2e3842cd0
7 changed files with 42 additions and 11 deletions
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('records', function (Blueprint $table) {
$table->text('search')->default("");
$table->index('search');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('records', function (Blueprint $table) {
$table->dropColumn('search');
$table->dropIndex('search');
});
}
};
-1
View File
@@ -214,7 +214,6 @@ class RecordController extends Controller
->parentsLimit(100)
->run();
if ($graph->records->isEmpty()) {
return $this->svelte->render(
layout: "channel",
+1 -1
View File
@@ -49,7 +49,7 @@ final class FilterParser
"eqfalse" => false,
"netrue" => true,
"nefalse" => false,
"regex" => "%{$value}%",
"regex" => "%" . strtolower($value) . "%",
"gt" => is_numeric($value) ? floatval($value) : $value,
"gte" => is_numeric($value) ? floatval($value) : $value,
"lt" => is_numeric($value) ? floatval($value) : $value,
-1
View File
@@ -148,7 +148,6 @@ final class Query
}
$query = $this->orderByQuery($query);
return $query->get()->map(function ($r) {
$r->isRoot = true;
return $r;
+3 -1
View File
@@ -4,6 +4,7 @@ namespace Lucent\Record;
use JsonSerializable;
use stdClass;
use Illuminate\Support\Str;
class Record implements JsonSerializable
{
@@ -23,6 +24,7 @@ class Record implements JsonSerializable
public function toDB(): array
{
$searchIndex = trim(Str::lower(collect($this->data)->values()->join(" ")." ". $this->_file?->originalName ?? ""));
return [
"id" => $this->id,
"status" => $this->status->value,
@@ -30,6 +32,7 @@ class Record implements JsonSerializable
"_sys" => json_encode($this->_sys),
"_file" => json_encode($this->_file),
"data" => json_encode($this->data),
"search" => $searchIndex,
];
}
@@ -61,5 +64,4 @@ class Record implements JsonSerializable
}
}
+1
View File
@@ -13,6 +13,7 @@ class RecordRepo
public static function create(Record $record): void
{
$recordToDB = $record->toDB();
DB::table("records")->insert($recordToDB);
}