Attributes
The model attributes in Raxos\Search\Attribute. Each one is a final readonly class. The #[Policy] attribute is documented separately on the Policy page.
#[Filter]
Raxos\Search\Attribute\Filter
A repeatable class attribute that maps an input property name to a filter instance.
public function __construct(
public string $property,
public FilterInterface $filter
)$propertyis the name akey:valuequery part or an HTTP parameter targets. The free text of a query is assigned to theqproperty.$filteris theFilterInterfaceinstance that narrows the query and returns a score.
use Raxos\Search\Attribute\Filter;
use Raxos\Search\Filter\{Exact, NaturalText};
#[Filter('author_id', filter: new Exact(modelKey: 'author_id'))]
#[Filter('q', filter: new NaturalText(keys: ['title', 'body']))]
final class Article extends Model { /* ... */ }See the filters concept and the filter class reference.
#[Preset]
Raxos\Search\Attribute\Preset
A repeatable class attribute describing a named set of default filter values for a model.
public function __construct(
public string $name,
public array $filters
)$nameidentifies the preset.$filtersis a map of filter property to default value.
The preset is stored on the generated search model for the application to read. The package itself does not apply presets automatically; you decide when and how to seed a search with a preset's values.
use Raxos\Search\Attribute\Preset;
#[Preset('recent', ['published' => '2024-01-01..'])]
final class Article extends Model { /* ... */ }To read the presets declared on a model, generate its search model directly with SearchModelGenerator:
use App\Model\Article;
use Raxos\Search\SearchModelGenerator;
$presets = SearchModelGenerator::generate(Article::class)->presets;#[SelectOption]
Raxos\Search\Attribute\SelectOption
A class attribute describing how a model is presented as type-ahead select options: which columns are searched, the ordering and the result limits.
public function __construct(
public array $searchKeys,
public ?string $order = null,
public bool $descending = false,
public int $limit = 25,
public ?int $emptyLimit = null
)$searchKeysare the columns matched with a substringLIKEsearch.$orderis the order-by column; it defaults to the first search key.$descendingorders descending when true.$limitcaps the results when a search term is present.$emptyLimitcaps the results with no search term; it defaults to$limit.
Like presets, this attribute carries configuration only. Reading it with reflection and building the query is left to the application. See the select options concept.
use Raxos\Search\Attribute\SelectOption;
#[SelectOption(searchKeys: ['name', 'email'], order: 'name', limit: 25, emptyLimit: 10)]
final class User extends Model { /* ... */ }Related
- Policy: the
#[Policy]attribute and its decision types. - Filter classes: the filter instances
#[Filter]points to. - SearchModel: the generated model these attributes end up on.