Documentation

typesense_search_functions.php

Table of Contents

Functions

typesense_search_supported()  : bool
Check whether the current ResourceSpace search can be handled by Typesense.
typesense_search_do_search()  : array<string|int, mixed>|false
Run a ResourceSpace search using Typesense and return ResourceSpace-compatible results.
typesense_search_get_refs()  : array<string|int, mixed>|false
Query Typesense and return matching resource refs in relevance order.
typesense_search_filter_by()  : string
Build a Typesense filter expression for simple ResourceSpace filters.
typesense_search_hydrate_refs()  : array<string|int, mixed>
Hydrate Typesense resource refs into the standard ResourceSpace search result structure.
typesense_search_request()  : array<string|int, mixed>|false
Send a request to the Typesense API.
typesense_search_ensure_collection()  : bool
Ensure that the Typesense resources collection exists.
typesense_search_get_document_data()  : array<string|int, mixed>|false
Build a Typesense document for a ResourceSpace resource.
typesense_search_index_resource()  : bool
Index a single ResourceSpace resource in Typesense.
typesense_search_delete_resource()  : bool
Delete a resource document from Typesense.
typesense_search_reindex_node_resources()  : int
Reindex all resources that are currently linked to a node.
typesense_search_reindex_all()  : array<string|int, mixed>
Reindex resources in batches.
typesense_search_index_document()  : bool
Index a Typesense document.
typesense_search_sync_related_keywords()  : bool
Synchronise ResourceSpace related keywords to Typesense synonyms.

Functions

typesense_search_supported()

Check whether the current ResourceSpace search can be handled by Typesense.

typesense_search_supported(string $search, array<string|int, mixed> $keywords, array<string|int, mixed> $node_bucket, array<string|int, mixed> $node_bucket_not, bool $return_disk_usage, bool $editable_only, bool $returnsql, bool $smartsearch) : bool
Parameters
$search : string

The original search string after ResourceSpace preprocessing.

$keywords : array<string|int, mixed>

Parsed search keywords.

$node_bucket : array<string|int, mixed>

Included node search buckets.

$node_bucket_not : array<string|int, mixed>

Excluded node search buckets.

$return_disk_usage : bool

Whether disk usage totals are requested.

$editable_only : bool

Whether only editable resources should be returned.

$returnsql : bool

Whether SQL should be returned instead of results.

$smartsearch : bool

Whether smart search mode is active.

Return values
bool

True if Typesense can handle the search, otherwise false.

Run a ResourceSpace search using Typesense and return ResourceSpace-compatible results.

typesense_search_do_search(string $search, mixed $restypes, array<string|int, mixed> $archive, mixed $fetchrows, bool $return_refs_only, PreparedStatementQuery $select, string $order_by, string $sort) : array<string|int, mixed>|false
Parameters
$search : string

Search string.

$restypes : mixed

Resource type filter.

$archive : array<string|int, mixed>

Archive state filter.

$fetchrows : mixed

Result limit or chunk details.

$return_refs_only : bool

Whether only resource refs should be returned.

$select : PreparedStatementQuery

Existing ResourceSpace SELECT fields.

$order_by : string

The order by SQL from the standard ResourceSpace search construction.

$sort : string
Return values
array<string|int, mixed>|false

ResourceSpace-compatible results, or false to fall back to core search.

typesense_search_get_refs()

Query Typesense and return matching resource refs in relevance order.

typesense_search_get_refs(string $search, mixed $restypes, array<string|int, mixed> $archive, mixed $fetchrows, mixed $order_by, mixed $sort) : array<string|int, mixed>|false
Parameters
$search : string

Search string.

$restypes : mixed

Resource type filter.

$archive : array<string|int, mixed>

Archive state filter.

$fetchrows : mixed

Result limit or chunk details.

$order_by : mixed
$sort : mixed
Return values
array<string|int, mixed>|false

Ordered resource refs, or false if Typesense should be bypassed.

typesense_search_filter_by()

Build a Typesense filter expression for simple ResourceSpace filters.

typesense_search_filter_by(mixed $restypes, array<string|int, mixed> $archive) : string
Parameters
$restypes : mixed

Resource type filter.

$archive : array<string|int, mixed>

Archive state filter.

Return values
string

Typesense filter expression.

typesense_search_hydrate_refs()

Hydrate Typesense resource refs into the standard ResourceSpace search result structure.

typesense_search_hydrate_refs(array<string|int, mixed> $refs, int $total, mixed $fetchrows, bool $return_refs_only, PreparedStatementQuery $select, string $order_by) : array<string|int, mixed>
Parameters
$refs : array<string|int, mixed>

Ordered resource refs from Typesense.

$total : int

Total number of matches reported by Typesense.

$fetchrows : mixed

Result limit or chunk details.

$return_refs_only : bool

Whether only resource refs should be returned.

$select : PreparedStatementQuery

Existing ResourceSpace SELECT fields.

$order_by : string

The order by SQL from the standard ResourceSpace search construction.

Return values
array<string|int, mixed>

ResourceSpace-compatible search results.

typesense_search_request()

Send a request to the Typesense API.

typesense_search_request(string $method, string $endpoint[, array<string|int, mixed>|null $payload = null ]) : array<string|int, mixed>|false
Parameters
$method : string

HTTP method.

$endpoint : string

API endpoint beginning with a slash.

$payload : array<string|int, mixed>|null = null

Optional request payload.

Return values
array<string|int, mixed>|false

Decoded JSON response, or false on failure.

typesense_search_ensure_collection()

Ensure that the Typesense resources collection exists.

typesense_search_ensure_collection() : bool
Return values
bool

True if the collection exists or was created.

typesense_search_get_document_data()

Build a Typesense document for a ResourceSpace resource.

typesense_search_get_document_data(int $resource) : array<string|int, mixed>|false
Parameters
$resource : int

Resource ID.

Return values
array<string|int, mixed>|false

Typesense document data, or false if the resource cannot be indexed.

typesense_search_index_resource()

Index a single ResourceSpace resource in Typesense.

typesense_search_index_resource(int $resource) : bool
Parameters
$resource : int

Resource ID.

Return values
bool

True if the resource was indexed successfully.

typesense_search_delete_resource()

Delete a resource document from Typesense.

typesense_search_delete_resource(int $resource) : bool
Parameters
$resource : int

Resource ID.

Return values
bool

True if the delete request succeeded.

typesense_search_reindex_node_resources()

Reindex all resources that are currently linked to a node.

typesense_search_reindex_node_resources(int $node) : int
Parameters
$node : int

Node ID.

Return values
int

Number of resources successfully reindexed.

typesense_search_reindex_all()

Reindex resources in batches.

typesense_search_reindex_all([int $limit = 100 ][, int $after = 0 ]) : array<string|int, mixed>
Parameters
$limit : int = 100

Maximum number of resources to index in this batch.

$after : int = 0

Only index resources with refs greater than this value.

Return values
array<string|int, mixed>

Batch indexing summary.

typesense_search_index_document()

Index a Typesense document.

typesense_search_index_document(array<string|int, mixed> $document) : bool
Parameters
$document : array<string|int, mixed>

Typesense document data.

Return values
bool

True if the document was indexed successfully.

Synchronise ResourceSpace related keywords to Typesense synonyms.

typesense_search_sync_related_keywords() : bool

Creates or updates synonym groups in the configured Typesense collection based on ResourceSpace related keyword relationships so that searches automatically match related terms using OR-style expansion.

Return values
bool

True if the sync completed successfully.

On this page

Search results