Documentation

TsService
in package

Table of Contents

Properties

$tsClient  : Client|null

Methods

assignAliasToCollection()  : bool
Updates or creates an alias for a specific collection.
deleteAliasByName()  : array<string|int, mixed>
Deletes a specific alias by its name from TypeSense.
dirtyFlush()  : mixed
getAliases()  : mixed
getAllProductListingProducts()  : array<string|int, mixed>
Retrieves all products from the product listing.
getAllSupportProductListingProducts()  : array<string|int, mixed>
Retrieves all support products from the support listing.
getClient()  : Client
getCollectionDocument()  : mixed
getCollectionDocuments()  : mixed
getCollectionFieldsIndexStatus()  : array<string|int, mixed>
Retrieves the index status of fields in a given collection.
getCollections()  : mixed
getCollectionsWithoutAlias()  : array<string|int, mixed>
Returns an array of collections that are not pointed to by any alias.
getProduct()  : Product|false
Creates and retrieves a Product instance based on the provided slug.
getProductById()  : Product|false
Creates and retrieves a Product instance based on the provided ID.
getProductListing()  : array<string|int, mixed>
Retrieves a product listing based on the specified search query.
getProductListingMulti()  : array<string|int, mixed>
Performs a multi-search query for product listings and processes the results.
getSearchResults()  : SearchResult|null
Factory method to create and return a SearchResult object for the given search term.
getSupportProductListing()  : array<string|int, mixed>
Retrieves a support product listing based on the specified search query.
getSupportProductsMulti()  : array<string|int, mixed>
Performs a multi-search query for support products and processes the results.
getWebsiteAttributes()  : array<string|int, mixed>
Retrieves website attributes based on a specific tag filter.
hasAliasForCollection()  : bool
Checks whether any alias is pointing to the specified collection.
isAliasExists()  : mixed
isCollectionExists()  : mixed
performMultiSearch()  : array<string|int, mixed>
Performs a multi-search query processes the results.
removeCollectionIfUnused()  : array<string|int, mixed>
Deletes a specific collection if it is not referenced by any alias.
removeOldCollections()  : mixed
removeOldCollectionsWithBackup()  : int
Removes old TypeSense collections that are not used by any alias, while keeping the two most recent versions (based on timestamp suffix) for each logical group.
safeFlush()  : bool
Safely flushes and populates collections for the specified locale and country.
saveDataToCollection()  : mixed

Properties

Methods

assignAliasToCollection()

Updates or creates an alias for a specific collection.

public static assignAliasToCollection(string $aliasName, string $newCollectionName) : bool

If the alias already exists, it will be updated to point to the new collection.

Parameters
$aliasName : string

The alias name to be updated.

$newCollectionName : string

The name of the new collection to assign to the alias.

Return values
bool

Returns true on success, false on failure.

deleteAliasByName()

Deletes a specific alias by its name from TypeSense.

public static deleteAliasByName(string $aliasName) : array<string|int, mixed>
Parameters
$aliasName : string

The name of the alias to delete.

Return values
array<string|int, mixed>

Result of the deletion with 'success' and 'message'.

dirtyFlush()

public static dirtyFlush(string $safeFraze) : mixed
Parameters
$safeFraze : string

getAliases()

public static getAliases() : mixed

getAllProductListingProducts()

Retrieves all products from the product listing.

public static getAllProductListingProducts([int $page = 1 ][, int $perPage = 200 ][, array<string|int, mixed> $allProducts = [] ][, array<string|int, mixed> $commonParams = [] ]) : array<string|int, mixed>
Parameters
$page : int = 1
$perPage : int = 200
$allProducts : array<string|int, mixed> = []
$commonParams : array<string|int, mixed> = []
Return values
array<string|int, mixed>

The search result with ProductCard objects in place of raw product data.

getAllSupportProductListingProducts()

Retrieves all support products from the support listing.

public static getAllSupportProductListingProducts([int $page = 1 ][, int $perPage = 200 ][, array<string|int, mixed> $allProducts = [] ][, array<string|int, mixed> $commonParams = [] ]) : array<string|int, mixed>
Parameters
$page : int = 1
$perPage : int = 200
$allProducts : array<string|int, mixed> = []
$commonParams : array<string|int, mixed> = []
Return values
array<string|int, mixed>

The search result with ProductCard objects in place of raw product data.

getCollectionDocument()

public static getCollectionDocument(string $id, string $collectionName) : mixed
Parameters
$id : string
$collectionName : string

getCollectionDocuments()

public static getCollectionDocuments(string $collectionName) : mixed
Parameters
$collectionName : string

getCollectionFieldsIndexStatus()

Retrieves the index status of fields in a given collection.

public static getCollectionFieldsIndexStatus(string $collectionName) : array<string|int, mixed>

This function connects to the TypeSense client to retrieve metadata about a specific collection and processes the fields to return their indexing status.

  • It skips fields where the name is exactly ".*".
  • If a field name contains the ".*" pattern, the pattern is removed, and the resulting field name is used as the key in the result array.
  • The indexing status of each field is stored in the result array, where the key is the field name (with or without the ".*" pattern) and the value is the field's 'index' status (true or false).
Parameters
$collectionName : string

The name of the collection to retrieve fields for.

Return values
array<string|int, mixed>

An associative array where the keys are field names and the values are their indexing statuses.

getCollections()

public static getCollections() : mixed

getCollectionsWithoutAlias()

Returns an array of collections that are not pointed to by any alias.

public static getCollectionsWithoutAlias() : array<string|int, mixed>
Return values
array<string|int, mixed>

List of collection arrays (as returned by TypeSense) without alias.

getProduct()

Creates and retrieves a Product instance based on the provided slug.

public static getProduct(string $slug) : Product|false

This static method attempts to instantiate a Product with the given parameters. If an exception occurs during instantiation, it logs the exception and returns false.

Parameters
$slug : string

The unique slug for the product.

Return values
Product|false

Returns a Product instance if successful, or false if products was not found.

getProductById()

Creates and retrieves a Product instance based on the provided ID.

public static getProductById(string $id) : Product|false

This static method attempts to instantiate a Product with the given parameters. If an exception occurs during instantiation, it logs the exception and returns false.

Parameters
$id : string

The unique identifier for the product.

Return values
Product|false

Returns a Product instance if successful, or false if an exception is caught.

getProductListing()

Retrieves a product listing based on the specified search query.

public static getProductListing(array<string|int, mixed> $searchQuery) : array<string|int, mixed>

This method performs a search in the ListingCollection and processes the results. For each search result, it creates a ProductCard using the product's ID and card data. Any errors encountered during the creation of ProductCard instances are logged. The modified search results, with ProductCard objects replacing the raw data, are returned.

Parameters
$searchQuery : array<string|int, mixed>

The search parameters used to query the product listing.

Return values
array<string|int, mixed>

The search result with ProductCard objects in place of raw product data.

getProductListingMulti()

Performs a multi-search query for product listings and processes the results.

public static getProductListingMulti(array<string|int, mixed> $searchRequests[, array<string|int, mixed> $commonParams = [] ]) : array<string|int, mixed>

This method sends multiple search requests and processes the main search result, which is always the first result in the multi-search. It reindexes facet counts, creates ProductCard objects for each hit in the main result, and merges additional facet data from side queries back into the main result.

It also ensures that all missing facets from the complete product set are added to the main result by performing an additional search for all facets and merging any missing facets with the filtered ones.

Parameters
$searchRequests : array<string|int, mixed>

An array of search requests to be performed.

$commonParams : array<string|int, mixed> = []

Common parameters to be applied to all search requests.

Return values
array<string|int, mixed>

The processed main result, including hits and facet counts.

getSearchResults()

Factory method to create and return a SearchResult object for the given search term.

public static getSearchResults(string $searchTerm, int $page[, int $perPage = 20 ]) : SearchResult|null
Parameters
$searchTerm : string

The term to search for.

$page : int

The page number to search for.

$perPage : int = 20

The number of results per page.

Return values
SearchResult|null

The SearchResult object containing the search results for the provided term.

getSupportProductListing()

Retrieves a support product listing based on the specified search query.

public static getSupportProductListing(array<string|int, mixed> $searchQuery) : array<string|int, mixed>

This method performs a search in the SupportCollection and processes the results. For each search result, it creates a ProductCard using the product's ID and card data. Any errors encountered during the creation of ProductCard instances are logged. The modified search results, with ProductCard objects replacing the raw data, are returned.

Parameters
$searchQuery : array<string|int, mixed>

The search parameters used to query the product listing.

Return values
array<string|int, mixed>

The search result with ProductCard objects in place of raw product data.

getSupportProductsMulti()

Performs a multi-search query for support products and processes the results.

public static getSupportProductsMulti(array<string|int, mixed> $searchRequests[, array<string|int, mixed> $commonParams = [] ]) : array<string|int, mixed>

This method sends multiple search requests and processes the main search result, which is always the first result in the multi-search. It reindexes facet counts, creates ProductCard objects for each hit in the main result, and merges additional facet data from side queries back into the main result.

It also ensures that all missing facets from the complete product set are added to the main result by performing an additional search for all facets and merging any missing facets with the filtered ones.

Parameters
$searchRequests : array<string|int, mixed>

An array of search requests to be performed.

$commonParams : array<string|int, mixed> = []

Common parameters to be applied to all search requests.

Return values
array<string|int, mixed>

The processed main result, including hits and facet counts.

getWebsiteAttributes()

Retrieves website attributes based on a specific tag filter.

public static getWebsiteAttributes() : array<string|int, mixed>

This function searches for attributes using a wildcard query and filters the results by a specific tag obtained from the configuration.

It returns an array of attributes, where each attribute includes:

  • 'id': The pretty ID of the document, or an empty string if not available.
  • 'name': The name of the document, or an empty string if not available.
Return values
array<string|int, mixed>

An array of attributes, each containing 'id' and 'name'.

hasAliasForCollection()

Checks whether any alias is pointing to the specified collection.

public static hasAliasForCollection(string $collectionName) : bool
Parameters
$collectionName : string

The name of the collection to check.

Return values
bool

True if any alias points to the given collection, false otherwise.

isAliasExists()

public static isAliasExists(string $alias) : mixed
Parameters
$alias : string

isCollectionExists()

public static isCollectionExists(mixed $collectionName) : mixed
Parameters
$collectionName : mixed

performMultiSearch()

Performs a multi-search query processes the results.

public static performMultiSearch(string $collectionAllias, array<string|int, mixed> $searchRequests[, array<string|int, mixed> $commonParams = [] ]) : array<string|int, mixed>

This method sends multiple search requests and processes the main search result, which is always the first result in the multi-search. It reindexes facet counts, creates ProductCard objects for each hit in the main result, and merges additional facet data from side queries back into the main result.

It also ensures that all missing facets from the complete product set are added to the main result by performing an additional search for all facets and merging any missing facets with the filtered ones.

Parameters
$collectionAllias : string
$searchRequests : array<string|int, mixed>

An array of search requests to be performed.

$commonParams : array<string|int, mixed> = []

Common parameters to be applied to all search requests.

Return values
array<string|int, mixed>

The processed main result, including hits and facet counts.

removeCollectionIfUnused()

Deletes a specific collection if it is not referenced by any alias.

public static removeCollectionIfUnused(string $collectionName) : array<string|int, mixed>
Parameters
$collectionName : string

The name of the collection to delete.

Return values
array<string|int, mixed>

An array containing:

  • 'success' (bool): true if deleted, false otherwise
  • 'message' (string): status or error message

removeOldCollections()

public static removeOldCollections() : mixed

removeOldCollectionsWithBackup()

Removes old TypeSense collections that are not used by any alias, while keeping the two most recent versions (based on timestamp suffix) for each logical group.

public static removeOldCollectionsWithBackup() : int

A collection is considered part of the same group if it shares the same prefix (i.e., everything before the last two parts – datetime and timestamp).

This method helps retain recent backups in case a new index build fails.

Return values
int

Number of deleted collections.

safeFlush()

Safely flushes and populates collections for the specified locale and country.

public static safeFlush([int|null $blogId = null ]) : bool

This function ensures that all necessary collections (Attributes, Products, Banners, Listings, Search, and Product Groups) are populated with updated data for the provided locale and country. Each collection's populateCollection method is called to update the data accordingly.

Parameters
$blogId : int|null = null
Return values
bool

saveDataToCollection()

public static saveDataToCollection(array<string|int, mixed> $data, string $collectionName[, bool $logProgress = true ]) : mixed
Parameters
$data : array<string|int, mixed>
$collectionName : string
$logProgress : bool = true

        
On this page

Search results