Use meilisearch in nav search

This commit is contained in:
2025-10-23 15:30:32 +02:00
parent 71bcf277f6
commit 6a25fd2700
7 changed files with 648 additions and 12 deletions

View File

@@ -3,7 +3,6 @@
namespace App\Livewire;
use App\Models\Episode;
use App\Models\Gallery;
use Livewire\Component;
use Illuminate\Support\Facades\Auth;
@@ -18,22 +17,15 @@ class NavLiveSearch extends Component
public function render()
{
$episodes = [];
$randomimage = null;
if ($this->navSearch != '') {
$episodes = Episode::with('gallery')->where('title', 'like', '%'.$this->navSearch.'%')
->orWhere('title_jpn', 'like', '%'.$this->navSearch.'%')
->when(Auth::guest(), fn ($query) => $query->withoutTags(['loli', 'shota']))
->take(10)
$episodes = Episode::search($this->navSearch)
->when(Auth::guest(), fn ($query) => $query->whereNotIn('tags', ['Loli', 'Shota']))
->take(7)
->get();
$randomimage = Gallery::all()
->random(1)
->first();
}
return view('livewire.nav-live-search', [
'episodes' => $episodes,
'randomimage' => $randomimage,
'query' => $this->navSearch,
'hide' => empty($this->navSearch),
]);

View File

@@ -9,6 +9,7 @@ use App\Models\PopularDaily;
use Conner\Tagging\Taggable;
use Laravelista\Comments\Commentable;
use Laravel\Scout\Searchable;
use Maize\Markable\Markable;
use Maize\Markable\Models\Like;
@@ -26,11 +27,40 @@ class Episode extends Model implements Sitemapable
{
use Commentable, Markable, Taggable;
use HasFactory;
use Searchable;
protected static $marks = [
Like::class
];
/**
* Get the name of the index associated with the model.
*/
public function searchableAs(): string
{
return 'episodes_index';
}
/**
* Get the indexable data array for the model.
*
* @return array<string, mixed>
*/
public function toSearchableArray()
{
return [
'title' => $this->title,
'title_search' => $this->title_search,
'title_jpn' => $this->title_jpn,
'slug' => $this->slug,
'description' => $this->description,
'view_count' => $this->view_count,
'tags' => $this->tagNames(),
'release_date' => $this->release_date,
'created_at' => $this->created_at,
];
}
/**
* Get the studio for the Hentai.
*/