Relevance Ranking Development Tutorials, Guides & Insights
Unlock 1+ expert-curated relevance ranking tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your relevance ranking skills on DeveloperBreeze.
Adblocker Detected
It looks like you're using an adblocker. Our website relies on ads to keep running. Please consider disabling your adblocker to support us and access the content.
Tutorial
php
Implementing Full-Text Search in Laravel
In app/Http/Controllers/SearchController.php, define the index and search methods:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class SearchController extends Controller
{
public function search(Request $request)
{
$query = $request->input('query');
if (empty($query) || strlen($query) < 4) {
return redirect()->route('search.index')->withErrors('Search term must be at least 4 characters long.');
}
// Perform full-text search with MATCH...AGAINST
$posts = DB::table('posts')
->select('id', 'title', 'content')
->whereRaw("MATCH(title, content) AGAINST(? IN BOOLEAN MODE)", ['"' . $query . '"'])
->get();
return view('search.index', [
'posts' => $posts,
'query' => $query,
]);
}
}Nov 16, 2024
Read More