Repository navigation
SearchIndexableReadModel
Pair\Search\SearchIndexableReadModel is the small contract for read models that can publish a search-specific document shape.
It extends ReadModel, so the same object can keep one API-facing representation through toArray() and one search-facing representation through searchDocument().
use Pair\Search\SearchIndexableReadModel;
final readonly class ProductReadModel implements SearchIndexableReadModel {
/**
* Build the product read model.
*/
public function __construct(
public int $id,
public string $title,
public bool $active,
public string $category
) {}
/**
* Return the default Meilisearch index UID for products.
*/
public static function searchIndexUid(): string {
return 'products';
}
/**
* Return the primary key field for indexed products.
*/
public static function searchPrimaryKey(): string {
return 'id';
}
/**
* Export the public API representation.
*
* @return array<string, mixed>
*/
public function toArray(): array {
return [
'id' => $this->id,
'title' => $this->title,
];
}
/**
* Export the search-specific document representation.
*
* @return array<string, mixed>
*/
public function searchDocument(): array {
return [
'id' => $this->id,
'title' => $this->title,
'is_active' => $this->active,
'category' => $this->category,
];
}
}Search indexes often need fields that should not be returned directly from JSON APIs, such as denormalized flags, category labels, tenant filters, or searchable text bundles.
Keeping toArray() and searchDocument() separate makes that boundary explicit.
searchIndexUid(): stringsearchPrimaryKey(): stringsearchDocument(): array
MeilisearchClient::indexReadModels(...) uses these methods when the read model implements this contract.
See also: MeilisearchClient, ReadModel, RecordMapper, Integrations.
Home · Setup · Configuration
Build with Pair 4
- Generator
- Controllers and responses
- Read models
- ActiveRecord and queries
- Forms and validation
- PairUI.js and HTML fragments
APIs and authentication
- API guide and CRUD
- Middleware and rate limits
- Users, sessions, and ACL
- Passkeys and social login
- Native mobile setup
Integrate and operate
- Integrations
- Runtime extensions and adapter keys
- Cache and cache stores
- Logs and observability
- PWA and push
- Packages and distribution
- Upgrade to v4