Class Reference

Key classes in the CelerSearch architecture.

Core Classes

BaseIndex

Abstract base class for all index types.

Class: CelerSearch\Indices\BaseIndex

Abstract Methods:

MethodReturnDescription
init()voidInitialize from config (protected)
get_settings()IndexSettingsDefine index settings
is_supported(IndexCandidate)boolFast type check
should_index(IndexCandidate)boolPer-item index decision
get_candidates(int $page, int $batch_size)IndexCandidatePaginated items
get_candidates_by_ids(array $ids)IndexCandidateItems by ID
get_candidate_count()intTotal count
get_candidate_objects(IndexCandidate)IIndexableObjectTransform to indexable records
format_autocomplete_hit(array $hit)array|nullFormat a hit for autocomplete display
get_autocomplete_status_filter(string $context)array|nullStatus filter for autocomplete ('frontend' or 'admin')

Public Methods:

PHP
// 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:

PHP
// 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:

MethodReturnDescription
init()voidCreate the API client (called from the constructor)
search(BaseIndex, string $query, array $params = [])IndexResponseExecute a search
format_search_params(array $params)arrayConvert normalized params to engine syntax (protected)
sync_item(BaseIndex, IIndexableObject)IndexResponseUpsert one document
delete_item(BaseIndex, IIndexableObject)IndexResponseDelete one document
count_items(BaseIndex)IndexResponseCount indexed documents (ValueResponse)
check_index(BaseIndex)IndexResponseCheck whether the index exists
touch_index(BaseIndex)IndexResponseCreate the index if it doesn't exist
clear_index(BaseIndex)IndexResponseDelete all documents
delete_index(BaseIndex)IndexResponseDelete the index
push_settings(BaseIndex)IndexResponsePush index settings to the engine
build_settings(BaseIndex)arrayMap IndexSettings to the engine's settings payload
list_documents(BaseIndex, int $offset, int $limit, array $fields = [])IndexResponsePaginated documents (DocumentListResponse)
get_document(BaseIndex, string $id)IndexResponseSingle document by primary key (ValueResponse)
get_index_config(BaseIndex)IndexResponseEngine-side effective settings (ValueResponse)
health_check()boolIs the engine reachable?
wait_for_completion(IndexResponse, int $timeout_ms = 5000)boolBlock 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

PHP
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, excerpt
  • author - Author object (filterable via author.display_name)
  • taxonomies / taxonomies_hierarchical - Terms grouped per taxonomy
  • images - Post image URLs
  • permalink - Post URL
  • created_at / updated_at - Timestamps
  • status - Post status
  • type_label - Post type label

ProductsIndex

Indexes WooCommerce products.

Class: CelerSearch\Indices\ProductsIndex

Configuration:

  • exclude_sold_out - Exclude out-of-stock products
  • exclude_catalog_visibility - Exclude hidden/catalog-only products

Notable Indexed Fields:

  • object_id, post_id, post_title, post_excerpt, short_description, content
  • sku - Product SKU
  • price, regular_price, sale_price (plus *_formatted display variants)
  • in_stock, stock_quantity, catalog_visibility
  • ratings - Object with total_ratings and average_rating
  • total_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 ID
  • number - Display order number
  • status / 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 total
  • date_timestamp / date_formatted - Order date
  • payment_method_title, shipping_method_title

Factories

IndexFactory

Creates index instances.

Class: CelerSearch\Factories\IndexFactory

PHP
// 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

PHP
// 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

PHP
// 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

PHP
// 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

PHP
// 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:

PHP
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

PHP
// 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\):

TypeExtra accessors
SuccessResponse—
ErrorResponseget_error_code(), get_error_message(), get_response_code(), get_response_body()
SearchResponseget_hits(), get_total_hits(), get_total_pages(), get_hits_per_page(), get_current_page(), get_facet_distribution(), get_facet_stats()
ValueResponseget_value()
DocumentListResponseget_documents(), get_total(), get_offset(), get_limit()
PHP
$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

PHP
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().