This module has all the tools and utilities to create a quick search engine for a Charcoal-based projects.
It features a very customizable search engines / search configuration that allows to search in SQL database tables, Charcoal Models or do custom search.
use \Charcoal\Search\SearchRunner;
use \Foo\Bar\CustomObject;
$searchRunner = new SearchRunner([
'search_config' => [
'ident' => 'my-custom-search',
'searches' => [
'foo' => new CustomSearch([
'logger' => $logger
'callback' => function($keyword) {
}
])
]
],
'model_factory' => $modelFactory,
'logger' => $logger
]);
// The results are an array like `['foo'=>[...], 'bar'=>[...]]`
$results = $searchRunner->search($keyword);
// Access log
$log = $searchRunner->searchLog();
// Differed access to results
$results = $searchRunner->results();The SearchRunner is instanciated with a single parameter, which contains the constructor options and class dependencies:
| Ident | Type | Description |
|---|---|---|
| logger | \Psr\Log\LoggerInterface |
A PSR-3 logger. |
| model_factory | \Charcoal\Factory\FactoryInterface |
A factory to create objects (and logs). |
| search_config | array |
A search config object |
The search config object contains the search ident as well as the various searches to run on objects.
| Ident | Type | Description |
|---|---|---|
| ident | string |
|
| searches | array |
The various searches to perform. |
Available search types, which are defined in the search config's searches:
customtable(todo)model(todo)
The custom search defines a callback function. This can either be a callable (a method or an object with an __invoke method) or a string (which will attempt to call the function of matching name on the Search Runner object).
The callback method must have the following signature:
array callback(string $keyword);
| Ident | Type | Description |
|---|---|---|
| callback | callback |
The table search is still todo.
The model search is still todo.