elastic basically finish

This commit is contained in:
xiaomlove
2022-03-26 04:27:04 +08:00
parent eb7451f574
commit 0bc1e2f9d3
17 changed files with 1146 additions and 33 deletions

View File

@@ -6,10 +6,8 @@ use App\Repositories\TagRepository;
use JeroenG\Explorer\Application\Explored;
use Laravel\Scout\Searchable;
class Torrent extends NexusModel implements Explored
class Torrent extends NexusModel
{
use Searchable;
protected $fillable = [
'name', 'filename', 'save_as', 'descr', 'small_descr', 'ori_descr',
'category', 'source', 'medium', 'codec', 'standard', 'processing', 'team', 'audiocodec',
@@ -79,12 +77,22 @@ class Torrent extends NexusModel implements Explored
{
return [
'id' => 'long',
'name' => 'text',
'descr' => 'text',
'name' => [
'type' => 'text',
'analyzer' => 'ik_max_word',
],
'descr' => [
'type' => 'text',
'analyzer' => 'ik_max_word',
],
'owner' => 'long',
'source' => 'long',
'leechers' => 'long',
'seeders' => 'long',
'added' => 'date',
'owner_info' => [
]
];
}
@@ -94,6 +102,7 @@ class Torrent extends NexusModel implements Explored
'id' => $this->id,
'name' => $this->name,
'descr' => $this->descr,
'owner' => $this->owner,
'source' => $this->source,
'leechers' => $this->leechers,
'seeders' => $this->seeders,
@@ -196,6 +205,11 @@ class Torrent extends NexusModel implements Explored
return true;
}
public function bookmarks(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Bookmark::class, 'torrentid');
}
public function user()
{
return $this->belongsTo(User::class, 'owner')->withDefault(User::getDefaultUserAttributes());
@@ -296,6 +310,11 @@ class Torrent extends NexusModel implements Explored
$query->where('visible', $visible);
}
public function torrent_tags(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(TorrentTag::class, 'torrent_id');
}
public function tags(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Tag::class, 'torrent_tags', 'torrent_id', 'tag_id')

View File

@@ -79,6 +79,32 @@ class User extends Authenticatable
'invites' => '邀请',
];
public function mappableAs(): array
{
return [
'id' => 'long',
'username' => [
'type' => 'text',
'analyzer' => 'ik_max_word',
],
'email' => [
'type' => 'text',
'analyzer' => 'ik_max_word',
],
'added' => 'date',
];
}
public function toSearchableArray()
{
return [
'id' => $this->id,
'username' => $this->username,
'email' => $this->email,
'added' => $this->added,
];
}
public function getClassTextAttribute(): string
{
return self::$classes[$this->class]['text'] ?? '';