Public Search API
Since ke_search 7.1, third-party extensions can execute searches programmatically via a public API. The same search logic as the frontend plugins is used (search phrase, filters, hooks), so results stay consistent.
Overview
- SearchService – Entry point. Inject
\Tpwd\. UseKe Search\ Service\ Search Service searchfor paginated full results, or(Search Request $request): Search Result searchfor all matching UIDs only (no pagination).Uids (Search Request $request): array - SearchRequest – Value object for search parameters (search word, starting points, filters, sort, limit, etc.).
- SearchResult – Value object with
get(raw index rows) andResults () get.Total Count ()
Basic usage
Inject the service and run a search with custom parameters:
use Tpwd\KeSearch\Domain\Search\SearchRequest;
use Tpwd\KeSearch\Service\SearchService;
class MyController
{
public function __construct(
private readonly SearchService $searchService
) {}
public function myAction(): void
{
$request = SearchRequest::fromArray([
'searchWord' => 'my search term',
'startingPoints' => '1,2,3', // comma-separated page UIDs
'limit' => 20,
'filter' => [123 => ['tag1', 'tag2']],
// optional: filter UID => selected option tags
]);
$result = $this->searchService->search($request);
$rows = $result->getResults();
// array of tx_kesearch_index rows
$total = $result->getTotalCount();
}
}
Advanced usage (same search, empty phrase)
This feature can be useful e.g. to run the same search as the current plugin (same filters, starting points, configuration) but without a search phrase, e.g. to use the result set for further processing.
Use this in a hook (e.g. modifyResultList) where you have
access to the plugin instance (
$p or
$this in a hook class
that receives the plugin):
use Tpwd\KeSearch\Domain\Search\SearchRequest;
use Tpwd\KeSearch\Service\SearchService;
// Inside a hook (e.g. modifyResultList) with access to the plugin $pObj:
$customRequest = SearchRequest::fromContext($pObj)->withEmptySearchPhrase();
$customResult = $this->searchService->search($customRequest);
$indexRows = $customResult->getResults();
// Use the rows for further processing
$total = $customResult->getTotalCount();
Search copies the current plugin's
configuration (FlexForm/conf), starting points, selected filters, sort order,
and results per page.
with returns a new request
with the same parameters but an empty search word.
All result UIDs only (efficient, no pagination)
You may need all matching index records (not just the first page) but only
the UIDs to load full records or content elsewhere. Use
search to run the same search without pagination and get a list
of UIDs (no full row data, efficient):
// Inside a hook with access to the plugin $pObj:
$customRequest = SearchRequest::fromContext($pObj)->withEmptySearchPhrase();
$uids = $this->searchService->searchUids($customRequest);
// list<int> of tx_kesearch_index UIDs
// Use $uids to load full records, build custom lists, etc.
foreach ($uids as $uid) {
// ...
}
search runs the same WHERE/ORDER as
the normal search but returns only UIDs and applies no limit, so you get every
matching index record's UID.
SearchRequest methods
Search– Build from an array (e.g.Request:: from Array (array $data): self search,Word starting,Points filter,page,sort,By Field sort,By Dir limit,conf).Search– Build from the current plugin/context (e.g. in a hook). Copies conf, filters, sort, limit.Request:: from Context (Search Context Interface $context): self with– Same parameters as the current request but withEmpty Search Phrase (): self searchset to empty.Word
SearchResult methods
get– Raw index rows (same structure asResults (): array tx_).kesearch_ index get– Total number of hits.Total Count (): int get– Tag counts for faceting, if requested (optional).Tags From Search Result (): ?array
SearchService::searchUids()
search– Runs the search with the same filters/context but no pagination and returns only UIDs:Uids (Search Request $request): array list<int>oftx_UIDs. Use when you need all matching IDs without full row data.kesearch_ index
Notes
- The API uses the same Db, Filters, and Searchphrase logic as the frontend. Hooks such as getQueryParts and modifySearchWords are applied when running a search via the API.
- When building a request with
from, the currentContext () Serveris copied so that language overlay and similar request-dependent behaviour work as in the frontend.Request Interface