Class Reference
Key classes in the CelerSearch architecture.
Core Classes
BaseIndex
Abstract base class for all index types.
Class: CelerSearch\Indices\BaseIndex
Abstract Methods:
| Method | Return | Description |
|---|---|---|
init() | void | Initialize from config (protected) |
get_settings() | IndexSettings | Define index settings |
is_supported(IndexCandidate) | bool | Fast type check |
should_index(IndexCandidate) | bool | Per-item index decision |
get_candidates(int $page, int $batch_size) | IndexCandidate | Paginated items |
get_candidates_by_ids(array $ids) | IndexCandidate | Items by ID |
get_candidate_count() | int | Total count |
get_candidate_objects(IndexCandidate) | IIndexableObject | Transform to indexable records |
format_autocomplete_hit(array $hit) | array|null | Format a hit for autocomplete display |
get_autocomplete_status_filter(string $context) | array|null | Status filter for autocomplete ('frontend' or 'admin') |
Public Methods:
// Identity
$index->get_id(): int;
$index->get_slug(): string;
$index->get_name(): string;
$index->get_type(): string;
// Associated service & stored configuration
$index->get_service(): BaseService;
$index->get_index_config(): IndexConfig;
// Search
$index->search(string $query, array $params = []): IndexResponse|SearchResponse|ErrorResponse;
// Document operations (delegate to the service)
$index->sync_item(IIndexableObject $item): IndexResponse|SuccessResponse|ErrorResponse;
$index->delete_item(IIndexableObject $item): IndexResponse|SuccessResponse|ErrorResponse;
$index->count_items(): IndexResponse|ValueResponse|ErrorResponse;
// Index lifecycle (delegate to the service)
$index->check(): IndexResponse|SuccessResponse|ErrorResponse; // does the index exist?
$index->touch(): IndexResponse|SuccessResponse|ErrorResponse; // create if missing
$index->clear(): IndexResponse|SuccessResponse|ErrorResponse; // delete all documents
$index->delete(): IndexResponse|SuccessResponse|ErrorResponse; // delete the index
$index->push_settings(): IndexResponse|SuccessResponse|ErrorResponse;
// Rebuilding
$index->rebuild_index(int $page): void; // one batch page; page 1 recreates the index
$index->rebuild_index_specific(array $object_ids): void;
$index->get_candidate_batch_size(): int;
// Attribute whitelists shown in the admin UI (override for curated labels)
$index->get_available_searchable_attributes(): array; // [['name' => ..., 'label' => ...], ...]
$index->get_available_filterable_attributes(): array;
$index->get_available_sortable_attributes(): array;
$index->required_filterable_attributes(): array; // default: ['status'] — always kept filterable
// Sorting
$index->resolve_sort(string $sort_key): array; // e.g. 'date' → ['created_at:desc']
BaseService
Abstract base class for search service providers.
Class: CelerSearch\Services\BaseService
Constructor & Concrete Methods:
// Stores the ServiceConfig as $this->details and calls init()
public function __construct(ServiceConfig $details);
$service->get_provider(): string; // e.g. 'meilisearch'
$service->get_settings(BaseIndex $index): array; // build_settings() + filters
$service->get_setting_impacts(): array; // setting key → 'reindex' | 'rebuild'
Abstract Methods:
| Method | Return | Description |
|---|---|---|
init() | void | Create the API client (called from the constructor) |
search(BaseIndex, string $query, array $params = []) | IndexResponse | Execute a search |
format_search_params(array $params) | array | Convert normalized params to engine syntax (protected) |
sync_item(BaseIndex, IIndexableObject) | IndexResponse | Upsert one document |
delete_item(BaseIndex, IIndexableObject) | IndexResponse | Delete one document |
count_items(BaseIndex) | IndexResponse | Count indexed documents (ValueResponse) |
check_index(BaseIndex) | IndexResponse | Check whether the index exists |
touch_index(BaseIndex) | IndexResponse | Create the index if it doesn't exist |
clear_index(BaseIndex) | IndexResponse | Delete all documents |
delete_index(BaseIndex) | IndexResponse | Delete the index |
push_settings(BaseIndex) | IndexResponse | Push index settings to the engine |
build_settings(BaseIndex) | array | Map IndexSettings to the engine's settings payload |
list_documents(BaseIndex, int $offset, int $limit, array $fields = []) | IndexResponse | Paginated documents (DocumentListResponse) |
get_document(BaseIndex, string $id) | IndexResponse | Single document by primary key (ValueResponse) |
get_index_config(BaseIndex) | IndexResponse | Engine-side effective settings (ValueResponse) |
health_check() | bool | Is the engine reachable? |
wait_for_completion(IndexResponse, int $timeout_ms = 5000) | bool | Block until an async task finishes |
See Custom providers for an implementation walkthrough. CelerSearch\Services\MeiliSearch is the reference implementation.
BaseObserver
Abstract base class for real-time sync observers.
Class: CelerSearch\Observers\BaseObserver
abstract class BaseObserver {
protected BaseIndex $index;
public function __construct(BaseIndex $index);
// Returns the observed index
public function get_index(): BaseIndex;
// Must implement - register WordPress hooks
abstract public function observe(): void;
// Sync a raw item (e.g. WP_Post) to the index
protected function sync_item($item): void;
// Delete a raw item from the index
protected function delete_item($item): void;
// Delete all records for a post ID (handles content splits)
protected function delete_post_records(int $post_id): void;
// Public wrappers used by queue processing
public function process_sync($item): void;
public function process_delete($item): void;
// Schedule sync/delete via the queue
protected function queue_sync(string $item_type, $item_id): void;
protected function queue_delete(string $item_type, $item_id): void;
// Check if queue processing should be used
protected function should_use_queue(): bool;
}
Built-in Indices
PostsIndex
Indexes WordPress posts, pages, and custom post types.
Class: CelerSearch\Indices\PostsIndex
Configuration:
post_types- Array of post types to index
Notable Indexed Fields:
object_id- Unique record ID (primary key)post_id- WordPress post ID (distinct attribute)title,content,excerptauthor- Author object (filterable viaauthor.display_name)taxonomies/taxonomies_hierarchical- Terms grouped per taxonomyimages- Post image URLspermalink- Post URLcreated_at/updated_at- Timestampsstatus- Post statustype_label- Post type label
ProductsIndex
Indexes WooCommerce products.
Class: CelerSearch\Indices\ProductsIndex
Configuration:
exclude_sold_out- Exclude out-of-stock productsexclude_catalog_visibility- Exclude hidden/catalog-only products
Notable Indexed Fields:
object_id,post_id,post_title,post_excerpt,short_description,contentsku- Product SKUprice,regular_price,sale_price(plus*_formatteddisplay variants)in_stock,stock_quantity,catalog_visibilityratings- Object withtotal_ratingsandaverage_ratingtotal_sales- Sales count (used for popularity sorting)attributes- WooCommerce product attributes (e.g.attributes.pa_color)taxonomies/taxonomies_hierarchical- Product categories, tags, etc.variations/variations_count- For variable products
OrdersIndex
Indexes WooCommerce orders (admin search only).
Class: CelerSearch\Indices\OrdersIndex
Configuration:
order_statuses- Array of order statuses to index
Notable Indexed Fields:
object_id-order-{id}(primary key)id/order_id- Order IDnumber- Display order numberstatus/status_name- Order status (slug and label)customer- Customer object (display_name,email)billing/shipping- Address objects (display_name,city,country, ...)items- Order line items (name,qty,sku)order_total/formatted_order_total- Order totaldate_timestamp/date_formatted- Order datepayment_method_title,shipping_method_title
Factories
IndexFactory
Creates index instances.
Class: CelerSearch\Factories\IndexFactory
// Create index by its integer database ID (NOT an IndexConfig object)
$index = IndexFactory::create(int $id): BaseIndex;
// Get all supported index types (filterable via celersearch_supported_indices)
$types = IndexFactory::get_supported_indices(): array;
// Create a throwaway index bound to a service, for connection testing
$index = IndexFactory::create_for_testing(ServiceConfig $service_config): BaseIndex;
IndexFactory::create() expects an integer ID. If you have an IndexConfig, pass $config->getId().
ServiceFactory
Creates service instances.
Class: CelerSearch\Factories\ServiceFactory
// Create service by its integer database ID
$service = ServiceFactory::create(int $id): BaseService;
// Create a service instance from an unsaved config (connection testing)
$service = ServiceFactory::create_for_testing(ServiceConfig|array $conf): BaseService;
ProviderFactory
Resolves registered search engine providers.
Class: CelerSearch\Factories\ProviderFactory
// Get all supported providers (filterable via celersearch_supported_providers)
$providers = ProviderFactory::get_supported_providers(): array;
// Get a single provider definition by slug (e.g. 'meilisearch'), or null
$provider = ProviderFactory::get_provider(string $slug): ?array;
ObserverFactory
Creates observers for indices.
Class: CelerSearch\Factories\ObserverFactory
// Create observer for specific index
$observer = ObserverFactory::create_for_index(BaseIndex $index): ?BaseObserver;
// Create all observers for active indices
$observers = ObserverFactory::create_all(): array;
SearchAreaFactory
Provides the available search area type descriptors (label, description, icon, category, features) shown in the Settings UI.
Class: CelerSearch\Factories\SearchAreaFactory
// All available area type descriptors (filterable via celersearch_area_types)
$types = SearchAreaFactory::get_available_types(): array;
// Single descriptor by type slug, or null
$type = SearchAreaFactory::get_type(string $type): ?array;
// Does a type exist?
SearchAreaFactory::type_exists(string $type): bool;
Search area classes (the runtime behavior) are registered separately via SearchAreaRegistry:
use CelerSearch\SearchAreas\SearchAreaRegistry;
add_action('celersearch_register_search_areas', function () {
SearchAreaRegistry::register('my_custom_search', \MyPlugin\SearchAreas\MyCustomSearchArea::class);
});
Response Types
IndexResponse (Abstract)
Base class for all response types.
Class: CelerSearch\Abstracts\IndexResponse
// Available on every response
$response->is_error_response(): bool;
// Async task info (MeiliSearch operations are asynchronous)
$response->has_task(): bool;
$response->get_task_id(): ?string;
$response->get_task_object(): mixed;
Concrete Types (CelerSearch\DataTransfer\IndexResponses\):
| Type | Extra accessors |
|---|---|
SuccessResponse | — |
ErrorResponse | get_error_code(), get_error_message(), get_response_code(), get_response_body() |
SearchResponse | get_hits(), get_total_hits(), get_total_pages(), get_hits_per_page(), get_current_page(), get_facet_distribution(), get_facet_stats() |
ValueResponse | get_value() |
DocumentListResponse | get_documents(), get_total(), get_offset(), get_limit() |
$response = $index->search('query');
if ($response->is_error_response()) {
error_log($response->get_error_message());
return;
}
foreach ($response->get_hits() as $hit) {
// ...
}
IndexResponseBuilder
Fluent builder used by providers to construct responses. The constructor takes the method name, which determines the concrete response type returned by build().
Class: CelerSearch\Builders\IndexResponseBuilder
use CelerSearch\Builders\IndexResponseBuilder;
// A 2xx response_code builds (by method name):
// 'search' → SearchResponse
// 'list_documents' → DocumentListResponse
// 'count_items' | 'get_document' | 'get_index_config' → ValueResponse
// anything else → SuccessResponse
// A non-2xx response_code always builds an ErrorResponse.
$response = (new IndexResponseBuilder('count_items'))
->response_code(200)
->response_body($raw)
->value(42)
->build();
$error = (new IndexResponseBuilder('sync_item'))
->response_code(500)
->error_message('Connection failed')
->build();
Fluent setters: method(), response_code(), response_body(), error_code(), error_message(), hits(), total_hits(), total_pages(), hits_per_page(), current_page(), facet_distribution(), facet_stats(), value(), documents(), total(), offset(), limit(), task_id(), task_object().