Searching
The search feature in Kinetics is managed by a component called SearchPipe. This feature allows users to search for keywords across all table columns that have been set as searchable.
Enabling Search
Section titled “Enabling Search”By default, columns will not be included in the global search to avoid excessively heavy database queries. You must explicitly enable it on each column using the searchable() method.
use Kinetics\Table;use Kinetics\Columns\TextColumn;
$table = Table::model(User::class) ->columns([ // This column will be ignored by the search feature TextColumn::make('id'),
// This column will be searched by SearchPipe TextColumn::make('name')->searchable(), TextColumn::make('email')->searchable(), ]) ->make();How SearchPipe Works
Section titled “How SearchPipe Works”When a request from the frontend sends a search parameter (e.g., ?search=john), SearchPipe will:
- Get a list of all columns that have the
searchablestatus. - Combine them into the Eloquent query builder using the
LIKEclause (or equivalent, depending on the database driver). - For regular columns, a query like
WHERE name LIKE '%john%' OR email LIKE '%john%'will be formed. - For relationship columns (e.g.,
company.name), awhereHasor automaticjoinmechanism will be formed so that the search can penetrate relationship boundaries.
Performance Note: The more columns you set as
searchable(), the more complex the resulting query will be. Enable this feature only on text columns that are truly relevant.