From 77c289164a987b9473fbf7a0dc694115aa42936d Mon Sep 17 00:00:00 2001 From: Peter Matseykanets Date: Fri, 2 Sep 2016 11:25:19 -0400 Subject: [PATCH] Initial commit. --- .editorconfig | 15 + .gitattributes | 10 + .gitignore | 2 + .styleci.yml | 3 + .travis.yml | 18 ++ CHANGELOG.md | 8 + CONTRIBUTING.md | 53 ++++ LICENSE.md | 21 ++ README.md | 89 ++++++ composer.json | 45 +++ phpunit.xml.dist | 22 ++ src/PostgresEngine.php | 407 ++++++++++++++++++++++++++ src/PostgresEngineServiceProvider.php | 18 ++ tests/AbstractTestCase.php | 16 + tests/PostgresEngineTest.php | 184 ++++++++++++ 15 files changed, 911 insertions(+) create mode 100755 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .styleci.yml create mode 100644 .travis.yml create mode 100755 CHANGELOG.md create mode 100755 CONTRIBUTING.md create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 composer.json create mode 100644 phpunit.xml.dist create mode 100644 src/PostgresEngine.php create mode 100644 src/PostgresEngineServiceProvider.php create mode 100644 tests/AbstractTestCase.php create mode 100644 tests/PostgresEngineTest.php diff --git a/.editorconfig b/.editorconfig new file mode 100755 index 0000000..cd8eb86 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +; This file is for unifying the coding style for different editors and IDEs. +; More information at http://editorconfig.org + +root = true + +[*] +charset = utf-8 +indent_size = 4 +indent_style = space +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9a73048 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +# Path-based git attributes +# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html + +# Ignore all test and documentation with "export-ignore". +/.gitattributes export-ignore +/.gitignore export-ignore +/.styleci.yml export-ignore +/.travis.yml export-ignore +/phpunit.xml.dist export-ignore +/tests export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b7ef35 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/vendor +composer.lock diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..916d27e --- /dev/null +++ b/.styleci.yml @@ -0,0 +1,3 @@ +preset: laravel + +linting: true diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..7c0ca5d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: php + +php: + - 5.6 + - 7.0 + - 7.1 + +env: + matrix: + - COMPOSER_FLAGS="--prefer-lowest" + - COMPOSER_FLAGS="" + +before_script: + - travis_retry composer self-update + - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source + +script: + - phpunit --coverage-text --coverage-clover=coverage.clover diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100755 index 0000000..0604b64 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# Changelog + +All notable changes to `pmatseykanets/laravel-hipchat-slash` will be documented in this file + +## [Unreleased] + +## [0.1.0] - 2016-09-02 +Experimental release. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100755 index 0000000..a8a71e2 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,53 @@ +# Contributing + +Contributions are **welcome** and will be fully **credited**. + +Please read and understand the contribution guide before creating an issue or pull request. + +## Etiquette + +This project is open source, and as such, the maintainers give their free time to build and maintain the source code +held within. They make the code freely available in the hope that it will be of use to other developers. It would be +extremely unfair for them to suffer abuse or anger for their hard work. + +Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the +world that developers are civilized and selfless people. + +It's the duty of the maintainer to ensure that all submissions to the project are of sufficient +quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. + +## Viability + +When requesting or submitting new features, first consider whether it might be useful to others. Open +source projects are used by many developers, who may have entirely different needs to your own. Think about +whether or not your feature is likely to be used by other users of the project. + +## Procedure + +Before filing an issue: + +- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. +- Check to make sure your feature suggestion isn't already present within the project. +- Check the pull requests tab to ensure that the bug doesn't have a fix in progress. +- Check the pull requests tab to ensure that the feature isn't already in progress. + +Before submitting a pull request: + +- Check the codebase to ensure that your feature doesn't already exist. +- Check the pull requests to ensure that another person hasn't already submitted the feature or fix. + +## Requirements + +- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). + +- **Add tests!** - Your patch won't be accepted if it doesn't have tests. + +- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. + +- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. + +- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. + +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. + +**Happy coding**! diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..e6aae03 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# The MIT License (MIT) + +Copyright (c) Peter Matseykanets + +> 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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ba7836f --- /dev/null +++ b/README.md @@ -0,0 +1,89 @@ +# PostrgeSQL Full Text Search Engine for Laravel Scout [WIP] + +[![Latest Version on Packagist](https://img.shields.io/packagist/v/pmatseykanets/laravel-scout-postgres.svg?style=flat-square)](https://packagist.org/packages/pmatseykanets/laravel-scout-postgres) +[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) +[![Build Status](https://img.shields.io/travis/pmatseykanets/laravel-scout-postgres/master.svg?style=flat-square)](https://travis-ci.org/pmatseykanets/laravel-scout-postgres) + +This package makes it easy to use native PostgreSQL Full Text Search capabilities with [Laravel Scout](http://laravel.com/docs/master/scout). + +## Contents + +- [Installation](#installation) + - [Setting up the HipChat Service](#setting-up-the-hipchat-service) +- [Usage](#usage) + - [Available Message methods](#available-message-methods) +- [Changelog](#changelog) +- [Testing](#testing) +- [Security](#security) +- [Contributing](#contributing) +- [Credits](#credits) +- [License](#license) + +## Installation + +You can install the package via composer: + +``` bash +composer require pmatseykanets/laravel-scout-postgres +``` + +You must install the service provider: + +```php +// config/app.php +'providers' => [ + ... + ScoutEngines\PostgresEngineServiceProvider::class, +], +``` + +Specify the database connection that should be used to access indexed documents in the Laravel Scout configuration file `config/scout.php`: + +```php +// config/scout.php +... +'pgsql' => [ + // Connection to use. See config/database.php + 'connection' => env('DB_CONNECTION', 'pgsql'), + // You may want to update index documents directly in PostgreSQL (i.e. via triggers). + // In this case you can set this value to false. + 'maintain_index' => true, +], +... +``` + +## Configuration + +TBD + +## Usage + +Please see the [official documentation](http://laravel.com/docs/master/scout) on how to use Laravel Scout. + + +## Testing + +``` bash +$ composer test +``` + +## Security + +If you discover any security related issues, please email pmatseykanets@gmail.com instead of using the issue tracker. + +## Changelog + +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. + +## Contributing + +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. + +## Credits + +- [Peter Matseykanets](https://github.com/pmatseykanets) +- [All Contributors](../../contributors) + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..0f00293 --- /dev/null +++ b/composer.json @@ -0,0 +1,45 @@ +{ + "name": "pmatseykanets/laravel-scout-postgres", + "description": "PostgreSQL FTS driver for Laravel Scout", + "keywords": [ + "laravel", + "laravel scout", + "search", + "postgresql", + "full text search" + ], + "homepage": "https://github.com/pmatseykanets/laravel-scout-postgresql", + "license": "MIT", + "authors": [ + { + "name": "Peter Matseykanets", + "email": "pmatseykanets@gmail.com", + "homepage": "https://github.com/pmatseykanets", + "role": "Developer" + } + ], + "require": { + "php": ">=5.6.4", + "illuminate/contracts": "~5.3", + "illuminate/database": "~5.3", + "illuminate/support": "~5.3", + "laravel/scout": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "5.*", + "mockery/mockery": "^0.9.5" + }, + "autoload": { + "psr-4": { + "ScoutEngines\\Postgres\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "ScoutEngines\\Postgres\\Test\\": "tests" + } + }, + "scripts": { + "test": "vendor/bin/phpunit" + } +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..f2eebe0 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,22 @@ + + + + + tests + + + + + src/ + + + diff --git a/src/PostgresEngine.php b/src/PostgresEngine.php new file mode 100644 index 0000000..6d735af --- /dev/null +++ b/src/PostgresEngine.php @@ -0,0 +1,407 @@ +resolver = $resolver; + $this->config = $config; + + $this->connect(); + } + + /** + * Update the given models in the index. + * + * @param \Illuminate\Database\Eloquent\Collection $models + * @return void + */ + public function update($models) + { + if (!$this->shouldMaintainIndex($models->first())) { + return; + } + + foreach ($models as $model) { + $this->performUpdate($model); + } + } + + /** + * Perform update of the given model. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return bool + */ + protected function performUpdate(Model $model) + { + $data = collect([$this->getIndexColumn($model) => $this->toVector($model)]); + + $query = $this->database + ->table($model->searchableAs()) + ->where($model->getKeyName(), '=', $model->getKey()); + + if (method_exists($model, 'searchableAdditionalArray')) { + $data = $data->merge($model->searchableAdditionalArray() ?: []); + } + + if (! $this->isExternalIndex($model) || $query->exists()) { + return $query->update($data->all()); + } + + return $query->insert( + $data->merge([ + $model->getKeyName() => $model->getKey() + ])->all() + ); + } + + /** + * Get the indexed value for a given model. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return string + */ + protected function toVector(Model $model) + { + $fields = collect($model->toSearchableArray()); + + $select = $fields->map(function ($value) { + return $value === null ? '' : $value; + })->map(function ($_, $key) use ($model) { + if ($label = $this->rankFieldWeightLabel($model, $key)) { + return "setweight(to_tsvector(?), '$label')"; + } + return 'to_tsvector(?)'; + })->implode(' || '); + + return $this->database + ->query() + ->selectRaw("$select AS tsvector", $fields->values()->all()) + ->value('tsvector'); + } + + /** + * Remove the given model from the index. + * + * @param \Illuminate\Database\Eloquent\Collection $models + * @return void + */ + public function delete($models) + { + $model = $models->first(); + + if (! $this->shouldMaintainIndex($model)) { + return; + } + + $indexColumn = $this->getIndexColumn($model); + $key = $model->getKeyName(); + + $ids = $models->pluck($key)->all(); + + return $this->database + ->table($model->searchableAs()) + ->whereIn($key, $ids) + ->update([$indexColumn => null]); + } + + /** + * Perform the given search on the engine. + * + * @param \Laravel\Scout\Builder $builder + * @return mixed + */ + public function search(Builder $builder) + { + return $this->performSearch($builder, $builder->limit); + } + + /** + * Perform the given search on the engine. + * + * @param \Laravel\Scout\Builder $builder + * @param int $perPage + * @param int $page + * @return mixed + */ + public function paginate(Builder $builder, $perPage, $page) + { + return $this->performSearch($builder, $perPage, $page); + } + + /** + * Perform the given search on the engine. + * + * @param \Laravel\Scout\Builder $builder + * @param int|null $perPage + * @param int $page + * @return array + */ + protected function performSearch(Builder $builder, $perPage = 0, $page = 1) + { + $indexColumn = $this->getIndexColumn($builder->model); + + // Build the query + $query = $this->database + ->table($builder->index ?: $builder->model->searchableAs()) + ->crossJoin($this->database->raw('plainto_tsquery(?) query')) + ->select($builder->model->getKeyName()) + ->selectRaw("{$this->rankingExpression($builder->model, $indexColumn)} AS rank") + ->whereRaw("$indexColumn @@ query") + ->orderBy('rank', 'desc') + ->orderBy('id'); + + if ($perPage > 0) { + $query->skip(($page - 1) * $perPage) + ->limit($perPage); + } + + $bindings = collect([$builder->query]); + + foreach ($builder->wheres as $key => $value) { + $query->where($key, $value); + $bindings->push($value); + } + + return $this->database + ->select($query->toSql(), $bindings->all()); + } + + /** + * Map the given results to instances of the given model. + * + * @param mixed $results + * @param \Illuminate\Database\Eloquent\Model $model + * @return Collection + */ + public function map($results, $model) + { + if (empty($results)) { + return Collection::make(); + }; + + $results = collect($results); + + $keys = $results + ->pluck($model->getKeyName()) + ->values() + ->all(); + + $models = $model->whereIn($model->getKeyName(), $keys) + ->get() + ->keyBy($model->getKeyName()); + + return $results->map(function ($result) use ($model, $models) { + return $models[$result->{$model->getKeyName()}]; + }); + } + + /** + * Connect to the database. + */ + protected function connect() + { + // Already connected + if ($this->database !== null) { + return; + } + + $connection = $this->resolver + ->connection($this->config('connection')); + + if ($connection->getDriverName() !== 'pgsql') { + throw new \InvalidArgumentException('Connection should use pgsql driver.'); + } + + $this->database = $connection; + } + + /** + * Build ranking expression that will be used in a search. + * ts_rank([ weights, ] vector, query [, normalization ]) + * ts_rank_cd([ weights, ] vector, query [, normalization ]) + * + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $indexColumn + * @return string + */ + protected function rankingExpression(Model $model, $indexColumn) + { + $args = collect([$indexColumn, 'query']); + + if ($weights = $this->rankWeights($model)) { + $args->prepend("'$weights'"); + } + + if ($norm = $this->rankNormalization($model)) { + $args->push($norm); + } + + $fn = $this->rankFunction($model); + + return "$fn({$args->implode(',')})"; + } + + /** + * Get rank function. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return int + */ + protected function rankFunction(Model $model) + { + $default = 'ts_rank'; + + $function = $this->option($model, 'rank.function', $default); + + return collect(['ts_rank', 'ts_rank_cd'])->contains($function) ? $function : $default; + } + + /** + * Get the rank weight label for a given field. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $field + * @return string + */ + protected function rankFieldWeightLabel(Model $model, $field) + { + $label = $this->option($model, "rank.fields.$field"); + + return collect(['A', 'B', 'C', 'D'])->contains($label) ? $label : ''; + } + + /** + * Get rank weights. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return string + */ + protected function rankWeights(Model $model) + { + $weights = $this->option($model, 'rank.weights'); + + if (! is_array($weights) || count($weights) !== 4) { + return ''; + } + + return '{'.implode(',', $weights).'}'; + } + + /** + * Get rank normalization. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return int + */ + protected function rankNormalization(Model $model) + { + return $this->option($model, 'rank.normalization', 0); + } + + /** + * See if the index should be maintained for a given model. + * + * @param \Illuminate\Database\Eloquent\Model|null $model + * @return bool + */ + protected function shouldMaintainIndex(Model $model = null) + { + if ((bool)$this->config('maintain_index', true) === false) { + return false; + } + + if ($model !== null) { + return $this->option($model, 'maintain_index', true); + } + } + + /** + * Get the name of the column that holds indexed documents. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return string + */ + protected function getIndexColumn(Model $model) + { + return $this->option($model, 'column', 'searchable'); + } + + /** + * See if indexed documents are stored in a external table. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return mixed + */ + protected function isExternalIndex(Model $model) + { + return $this->option($model, 'external', false); + } + + /** + * Get the model specific option value or a default. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $key + * @param mixed $default + * @return mixed + */ + protected function option(Model $model, $key, $default = null) + { + if (! method_exists($model, 'searchableOptions')) { + return $default; + } + + $options = $model->searchableOptions() ?: []; + + return array_get($options, $key, $default); + } + + /** + * Get the config value or a default. + * + * @param string $key + * @param mixed $default + * @return mixed + */ + protected function config($key, $default = null) + { + return array_get($this->config, $key, $default); + } +} diff --git a/src/PostgresEngineServiceProvider.php b/src/PostgresEngineServiceProvider.php new file mode 100644 index 0000000..5ec26ad --- /dev/null +++ b/src/PostgresEngineServiceProvider.php @@ -0,0 +1,18 @@ +extend('pgsql', function () { + return new PostgresEngine($this->app['db'], config('scout.pgsql', [])); + }); + } +} diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php new file mode 100644 index 0000000..b04807c --- /dev/null +++ b/tests/AbstractTestCase.php @@ -0,0 +1,16 @@ +getEngine(); + + $this->assertInstanceOf(PostgresEngine::class, $engine); + } + + public function test_update_adds_object_to_index() + { + list($engine, $db) = $this->getEngine(); + + $db->shouldReceive('query') + ->andReturn($query = Mockery::mock('stdClass')); + $query->shouldReceive('selectRaw') + ->with('to_tsvector(?) AS tsvector', ['Foo']) + ->andReturnSelf(); + $query->shouldReceive('value') + ->with('tsvector') + ->andReturn('foo'); + + $db->shouldReceive('table') + ->andReturn($table = Mockery::mock('stdClass')); + $table->shouldReceive('where') + ->with('id', '=', 1) + ->andReturnSelf(); + $table->shouldReceive('update') + ->with(['searchable' => 'foo']); + + $engine->update(Collection::make([new TestModel()])); + } + + public function test_update_do_nothing_if_index_maintenance_turned_off_globally() + { + list($engine) = $this->getEngine(['maintain_index' => false]); + + $engine->update(Collection::make([new TestModel()])); + } + + public function test_delete_removes_object_from_index() + { + list($engine, $db) = $this->getEngine(); + + $db->shouldReceive('table') + ->andReturn($table = Mockery::mock('stdClass')); + $table->shouldReceive('whereIn') + ->with('id', [1]) + ->andReturnSelf(); + $table->shouldReceive('update') + ->with(['searchable' => null]); + + $engine->delete(Collection::make([new TestModel()])); + } + + public function test_delete_do_nothing_if_index_maintenance_turned_off_globally() + { + list($engine, $db) = $this->getEngine(['maintain_index' => false]); + + $db->shouldReceive('table') + ->andReturn($table = Mockery::mock('stdClass')); + $table->shouldReceive('whereIn') + ->with('id', [1]) + ->andReturnSelf(); + $table->shouldReceive('update') + ->with(['searchable' => null]); + + $engine->delete(Collection::make([new TestModel()])); + } + + public function test_search() + { + list($engine, $db) = $this->getEngine(); + + $db->shouldReceive('table') + ->andReturn($table = Mockery::mock('stdClass')); + $db->shouldReceive('raw') + ->with('plainto_tsquery(?) query') + ->andReturn('plainto_tsquery(?) query'); + + $table->shouldReceive('crossJoin')->with('plainto_tsquery(?) query')->andReturnSelf() + ->shouldReceive('select')->with('id')->andReturnSelf() + ->shouldReceive('selectRaw')->andReturnSelf() + ->shouldReceive('whereRaw')->andReturnSelf() + ->shouldReceive('orderBy')->with('rank', 'desc')->andReturnSelf() + ->shouldReceive('orderBy')->with('id')->andReturnSelf() + ->shouldReceive('skip')->with(0)->andReturnSelf() + ->shouldReceive('limit')->with(5)->andReturnSelf() + ->shouldReceive('where')->with('bar', 1)->andReturnSelf() + ->shouldReceive('toSql'); + + $db->shouldReceive('select')->with(null, ['foo', 1]); + + $builder = new Builder(new TestModel(), 'foo'); + $builder->where('bar', 1)->take(5); + + $engine->search($builder); + } + + public function test_map_correctly_maps_results_to_models() + { + list($engine) = $this->getEngine(); + + $model = Mockery::mock('StdClass'); + $model->shouldReceive('getKeyName')->andReturn('id'); + $model->shouldReceive('whereIn')->once()->with('id', [1])->andReturn($model); + $model->shouldReceive('get')->once()->andReturn(Collection::make([new TestModel()])); + + $results = $engine->map( + json_decode('[{"id": 1, "rank": 0.33}]') + , $model); + + $this->assertCount(1, $results); + } + + protected function getEngine($config = []) + { + $resolver = Mockery::mock(ConnectionResolverInterface::class); + $resolver->shouldReceive('connection') + ->andReturn($db = Mockery::mock(Connection::class)); + + $db->shouldReceive('getDriverName')->andReturn('pgsql'); + + return [new PostgresEngine($resolver, $config), $db]; + } +} + +class TestModel extends Model +{ + public $id = 1; + + public $text = 'Foo'; + + protected $searchableOptions = []; + + protected $searchableAdditionalArray = []; + + public function searchableAs() + { + return 'searchable'; + } + + public function getKeyName() + { + return 'id'; + } + + public function getKey() + { + return $this->id; + } + + public function getTable() + { + return 'table'; + } + + public function toSearchableArray() + { + return ['text' => $this->text]; + } + + public function searchableOptions() + { + return $this->searchableOptions; + } + + public function searchableAdditionalArray() + { + return $this->searchableAdditionalArray; + } +} \ No newline at end of file