locomotivemtl / charcoal-search
Charcoal Search Engine tools and utilities
Installs: 1 442
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 15
Forks: 1
Open Issues: 0
Requires
- php: >=5.6.0 || >=7.0
- locomotivemtl/charcoal-app: ~0.2
- locomotivemtl/charcoal-core: ~0.4
- locomotivemtl/charcoal-object: ~0.2
- psr/log: ^1.0
Requires (Dev)
- cache/void-adapter: ^0.3
- phpunit/phpunit: ^5.7 || ^6.5
- satooshi/php-coveralls: ^2.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-10-25 16:54:07 UTC
README
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.
Table of content
- How to install
- Example usage
- Constructor options
- Search config
- Search types
- Custom search
- Custom options
- Model search
- Table search
- Custom search
- Search log
- Charcoal-admin integration
- Development
How to install
The preferred (and only supported) way of installing charcoal-search is with composer:
★ composer require locomotivemtl/charcoal-search
Dependencies
Example usage
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();
Constructor options
The SearchRunner
is instanciated with a single parameter, which contains the constructor options and class dependencies:
Search config
The search config object contains the search ident as well as the various searches to run on objects.
Search types
Available search types, which are defined in the search config's searches:
custom
table
(todo)model
(todo)
Custom search
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);
Custom options
Table search
The table
search is still todo.
Model search
The model
search is still todo.
Search log
Every search is automatically logged to (SQL) storage.
Charcoal-admin integration
The search-log object comes by default with full metadata to display in charcoal-admin. Visit at [[your-site.com]]/admin/object/collection?obj-type=charcoal/search/search-log.
There are 2 widgets also available to visualize logs:
charcoal/admin/widget/search/no-results-search
charcoal/admin/widget/search/top-search
Development
To install the development environment:
★ composer install --prefer-source
To run the scripts (phplint, phpcs and phpunit):
★ composer test
Development dependencies
phpunit/phpunit
squizlabs/php_codesniffer
satooshi/php-coveralls
Continuous Integration
Coding Style
All Charcoal modules follow the same coding style and charcoal-search
is no exception. For PHP:
- PSR-1
- PSR-2
- PSR-4, autoloading is therefore provided by Composer
- phpDocumentor
- Read the phpcs.xml file for all the details on code style.
Coding style validation / enforcement can be performed with
composer phpcs
. An auto-fixer is also available withcomposer phpcbf
.
Authors
- Mathieu Ducharme mat@locomotive.ca
Changelog
- Unreleased
The MIT License (MIT)
Copyright © 2016 Locomotive inc.
See Authors.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.