From 1959292f29ea429b410c2119d8690e8ef4633087 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 08:40:26 -0400 Subject: [PATCH 01/21] Add getUnqualifiedScoutKeyName method --- src/Builder.php | 2 +- src/Searchable.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Builder.php b/src/Builder.php index 851fcf28..9bd89df8 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -444,7 +444,7 @@ protected function getTotalCount($results) $ids = $engine->mapIdsFrom( $results, - Str::afterLast($this->model->getScoutKeyName(), '.') + $this->model->getUnqualifiedScoutKeyName() )->all(); if (count($ids) < $totalCount) { diff --git a/src/Searchable.php b/src/Searchable.php index 3e2f0e8e..ad7089d1 100644 --- a/src/Searchable.php +++ b/src/Searchable.php @@ -2,6 +2,7 @@ namespace Laravel\Scout; +use Illuminate\Support\Str; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Collection as BaseCollection; @@ -389,6 +390,16 @@ public function getScoutKeyName() return $this->getQualifiedKeyName(); } + /** + * Get the unqualified Scout key name. + * + * @return string + */ + public function getUnqualifiedScoutKeyName() + { + return Str::afterLast($this->getScoutKeyName(), '.'); + } + /** * Determine if the current class should use soft deletes with searching. * From 6146bb78298f55288eab6fc7b18e09d5a5d0fed9 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 08:41:52 -0400 Subject: [PATCH 02/21] Add RemoveableScoutCollection tests --- tests/Unit/RemoveableScoutCollectionTest.php | 58 ++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/Unit/RemoveableScoutCollectionTest.php diff --git a/tests/Unit/RemoveableScoutCollectionTest.php b/tests/Unit/RemoveableScoutCollectionTest.php new file mode 100644 index 00000000..977624d9 --- /dev/null +++ b/tests/Unit/RemoveableScoutCollectionTest.php @@ -0,0 +1,58 @@ +with('scout.after_commit', m::any())->andReturn(false); + Config::shouldReceive('get')->with('scout.soft_delete', m::any())->andReturn(false); + } + + protected function tearDown(): void + { + m::close(); + } + + public function test_get_queuable_ids() + { + $collection = RemoveableScoutCollection::make([ + new SearchableModel(['id' => 1]), + new SearchableModel(['id' => 2]), + ]); + + $this->assertEquals([1,2], $collection->getQueueableIds()); + } + + public function test_get_queuable_ids_resolves_custom_scout_keys() + { + $collection = RemoveableScoutCollection::make([ + new SearchCustomKeySearchableModel(['id' => 1]), + new SearchCustomKeySearchableModel(['id' => 2]), + new SearchCustomKeySearchableModel(['id' => 3]), + new SearchCustomKeySearchableModel(['id' => 4]), + ]); + + $this->assertEquals([ + 'custom-key.1', + 'custom-key.2', + 'custom-key.3', + 'custom-key.4', + ], $collection->getQueueableIds()); + } +} + +class SearchCustomKeySearchableModel extends SearchableModel +{ + public function getScoutKey() + { + return 'custom-key.'.$this->getKey(); + } +} \ No newline at end of file From 071c9de6e7a828ca1a844cce3397de83620e3ba5 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 08:43:08 -0400 Subject: [PATCH 03/21] Change order of update indexing so a custom key cannot be overridden and resolve deleting with custom key --- src/Engines/MeiliSearchEngine.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Engines/MeiliSearchEngine.php b/src/Engines/MeiliSearchEngine.php index e338f1b5..099826e1 100644 --- a/src/Engines/MeiliSearchEngine.php +++ b/src/Engines/MeiliSearchEngine.php @@ -5,6 +5,7 @@ use Illuminate\Support\LazyCollection; use Illuminate\Support\Str; use Laravel\Scout\Builder; +use Laravel\Scout\Jobs\RemoveableScoutCollection; use MeiliSearch\Client as MeiliSearchClient; use MeiliSearch\MeiliSearch; use MeiliSearch\Search\SearchResult; @@ -64,9 +65,9 @@ public function update($models) } return array_merge( - [$model->getKeyName() => $model->getScoutKey()], $searchableData, - $model->scoutMetadata() + $model->scoutMetadata(), + [$model->getKeyName() => $model->getScoutKey()], ); })->filter()->values()->all(); @@ -83,13 +84,17 @@ public function update($models) */ public function delete($models) { + if ($models->isEmpty()) { + return; + } + $index = $this->meilisearch->index($models->first()->searchableAs()); - $index->deleteDocuments( - $models->map->getScoutKey() - ->values() - ->all() - ); + $values = $models instanceof RemoveableScoutCollection + ? $models->pluck($models->first()->getUnqualifiedScoutKeyName()) + : $models->map->getScoutKey(); + + $index->deleteDocuments($values->all()); } /** @@ -244,7 +249,7 @@ public function mapIdsFrom($results, $key) */ public function keys(Builder $builder) { - $scoutKey = Str::afterLast($builder->model->getScoutKeyName(), '.'); + $scoutKey = $builder->model->getUnqualifiedScoutKeyName(); return $this->mapIdsFrom($this->search($builder), $scoutKey); } From d996a04bcd9ef2c7e9a8ad3d5df7a1ac423d5268 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 08:43:45 -0400 Subject: [PATCH 04/21] Return a RemoveableScoutCollection instance and fix key type when scout key is a string --- src/Jobs/RemoveFromSearch.php | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/Jobs/RemoveFromSearch.php b/src/Jobs/RemoveFromSearch.php index 565b71bf..caceb16c 100644 --- a/src/Jobs/RemoveFromSearch.php +++ b/src/Jobs/RemoveFromSearch.php @@ -15,7 +15,7 @@ class RemoveFromSearch implements ShouldQueue /** * The models to be removed from the search index. * - * @var \Illuminate\Database\Eloquent\Collection + * @var \Laravel\Scout\Jobs\RemoveableScoutCollection */ public $models; @@ -46,35 +46,27 @@ public function handle() * Restore a queueable collection instance. * * @param \Illuminate\Contracts\Database\ModelIdentifier $value - * @return \Illuminate\Database\Eloquent\Collection + * @return \Laravel\Scout\Jobs\RemoveableScoutCollection */ protected function restoreCollection($value) { if (! $value->class || count($value->id) === 0) { - return new EloquentCollection; + return new RemoveableScoutCollection; } - return new EloquentCollection( + return new RemoveableScoutCollection( collect($value->id)->map(function ($id) use ($value) { return tap(new $value->class, function ($model) use ($id) { - $keyName = $this->getUnqualifiedScoutKeyName( - $model->getScoutKeyName() - ); - - $model->forceFill([$keyName => $id]); + // The scout key may not be an integer. In this case, + // we will force a key type of string so it is not + // cast when retrieving it from the model. + $model->setKeyType( + is_string($id) ? 'string' : 'int' + )->forceFill([ + $model->getUnqualifiedScoutKeyName() => $id + ]); }); }) ); } - - /** - * Get the unqualified Scout key name. - * - * @param string $keyName - * @return string - */ - protected function getUnqualifiedScoutKeyName($keyName) - { - return Str::afterLast($keyName, '.'); - } } From 73227bb4ec49e7b3e7b7ca6e54e1fdb24da276cd Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 08:45:44 -0400 Subject: [PATCH 05/21] Add `RemoveFromSearch` meilisearch tests --- tests/Unit/MeiliSearchEngineTest.php | 72 +++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/tests/Unit/MeiliSearchEngineTest.php b/tests/Unit/MeiliSearchEngineTest.php index 4d80903a..4e554862 100644 --- a/tests/Unit/MeiliSearchEngineTest.php +++ b/tests/Unit/MeiliSearchEngineTest.php @@ -2,10 +2,14 @@ namespace Laravel\Scout\Tests\Unit; +use Illuminate\Container\Container; use Illuminate\Database\Eloquent\Collection; +use Illuminate\Support\Facades\Config; use Illuminate\Support\LazyCollection; use Laravel\Scout\Builder; +use Laravel\Scout\EngineManager; use Laravel\Scout\Engines\MeiliSearchEngine; +use Laravel\Scout\Jobs\RemoveFromSearch; use Laravel\Scout\Tests\Fixtures\EmptySearchableModel; use Laravel\Scout\Tests\Fixtures\SearchableModel; use Laravel\Scout\Tests\Fixtures\SoftDeletedEmptySearchableModel; @@ -18,6 +22,17 @@ class MeiliSearchEngineTest extends TestCase { + protected function setUp(): void + { + Config::shouldReceive('get')->with('scout.after_commit', m::any())->andReturn(false); + Config::shouldReceive('get')->with('scout.soft_delete', m::any())->andReturn(false); + } + + protected function tearDown(): void + { + m::close(); + } + public function test_update_adds_objects_to_index() { $client = m::mock(Client::class); @@ -43,6 +58,59 @@ public function test_delete_removes_objects_to_index() $engine->delete(Collection::make([new SearchableModel(['id' => 1])])); } + public function test_delete_removes_objects_to_index_with_a_custom_search_key() + { + $client = m::mock(Client::class); + $client->shouldReceive('index')->with('table')->andReturn($index = m::mock(Indexes::class)); + $index->shouldReceive('deleteDocuments')->once()->with(['my-meilisearch-key.5']); + + $engine = new MeiliSearchEngine($client); + $engine->delete(Collection::make([new MeiliSearchCustomKeySearchableModel(['id' => 5])])); + } + + public function test_delete_with_removeable_scout_collection_using_custom_search_key() + { + $job = new RemoveFromSearch(Collection::make([ + new MeiliSearchCustomKeySearchableModel(['id' => 5]) + ])); + + $job = unserialize(serialize($job)); + + $client = m::mock(Client::class); + $client->shouldReceive('index')->with('table')->andReturn($index = m::mock(Indexes::class)); + $index->shouldReceive('deleteDocuments')->once()->with(['my-meilisearch-key.5']); + + $engine = new MeiliSearchEngine($client); + $engine->delete($job->models); + } + + public function test_remove_from_search_job_uses_custom_search_key() + { + $job = new RemoveFromSearch(Collection::make([ + new MeiliSearchCustomKeySearchableModel(['id' => 5]) + ])); + + $job = unserialize(serialize($job)); + + Container::getInstance()->bind(EngineManager::class, function () { + $engine = m::mock(MeiliSearchEngine::class); + + $engine->shouldReceive('delete')->once()->with(m::on(function ($collection) { + $keyName = ($model = $collection->first())->getUnqualifiedScoutKeyName(); + + return $model->getAttributes()[$keyName] === 'my-meilisearch-key.5'; + })); + + $manager = m::mock(EngineManager::class); + + $manager->shouldReceive('engine')->andReturn($engine); + + return $manager; + }); + + $job->handle(); + } + public function test_search_sends_correct_parameters_to_meilisearch() { $client = m::mock(Client::class); @@ -171,7 +239,7 @@ public function test_returns_primary_keys_when_custom_array_order_present() $builder = m::mock(Builder::class); $model = m::mock(stdClass::class); - $model->shouldReceive(['getScoutKeyName' => 'table.custom_key']); + $model->shouldReceive(['getUnqualifiedScoutKeyName' => 'custom_key']); $builder->model = $model; $engine->shouldReceive('keys')->passthru(); @@ -300,7 +368,7 @@ public function test_a_model_is_indexed_with_a_custom_meilisearch_key() $client = m::mock(Client::class); $client->shouldReceive('index')->with('table')->andReturn($index = m::mock(Indexes::class)); $index->shouldReceive('addDocuments')->once()->with([[ - 'id' => 5, + 'id' => 'my-meilisearch-key.5' ]], 'id'); $engine = new MeiliSearchEngine($client); From aba856407b4d50fd2fa0977d0a7ff4c1c56d790c Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 08:53:49 -0400 Subject: [PATCH 06/21] Flush the container on tear down --- tests/Unit/MeiliSearchEngineTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Unit/MeiliSearchEngineTest.php b/tests/Unit/MeiliSearchEngineTest.php index 4e554862..4ad26a94 100644 --- a/tests/Unit/MeiliSearchEngineTest.php +++ b/tests/Unit/MeiliSearchEngineTest.php @@ -30,6 +30,7 @@ protected function setUp(): void protected function tearDown(): void { + Container::getInstance()->flush(); m::close(); } From 7bea1cc65f704bc430132de9dadb220b356cec8a Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 09:03:35 -0400 Subject: [PATCH 07/21] Remove unneeded tearDown --- tests/Unit/RemoveableScoutCollectionTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/Unit/RemoveableScoutCollectionTest.php b/tests/Unit/RemoveableScoutCollectionTest.php index 977624d9..408a42d4 100644 --- a/tests/Unit/RemoveableScoutCollectionTest.php +++ b/tests/Unit/RemoveableScoutCollectionTest.php @@ -16,11 +16,6 @@ protected function setUp(): void Config::shouldReceive('get')->with('scout.soft_delete', m::any())->andReturn(false); } - protected function tearDown(): void - { - m::close(); - } - public function test_get_queuable_ids() { $collection = RemoveableScoutCollection::make([ From 625ba1bd2971aaa9bc023058f131bde1547f96ac Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 09:16:38 -0400 Subject: [PATCH 08/21] Update algolia engine to delete using custom keys --- src/Engines/AlgoliaEngine.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Engines/AlgoliaEngine.php b/src/Engines/AlgoliaEngine.php index 3739ee6f..aea5acae 100644 --- a/src/Engines/AlgoliaEngine.php +++ b/src/Engines/AlgoliaEngine.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\LazyCollection; use Laravel\Scout\Builder; +use Laravel\Scout\Jobs\RemoveableScoutCollection; class AlgoliaEngine extends Engine { @@ -82,13 +83,17 @@ public function update($models) */ public function delete($models) { + if ($models->isEmpty()) { + return; + } + $index = $this->algolia->initIndex($models->first()->searchableAs()); - $index->deleteObjects( - $models->map(function ($model) { - return $model->getScoutKey(); - })->values()->all() - ); + $values = $models instanceof RemoveableScoutCollection + ? $models->pluck($models->first()->getUnqualifiedScoutKeyName()) + : $models->map->getScoutKey(); + + $index->deleteObjects($values->all()); } /** From 745ce0bf90d419e9107d0acdfc0578f6c542da23 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 09:16:48 -0400 Subject: [PATCH 09/21] Add Algolia deletion tests with custom keys --- tests/Unit/AlgoliaEngineTest.php | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/Unit/AlgoliaEngineTest.php b/tests/Unit/AlgoliaEngineTest.php index debe1b29..119ed1b3 100644 --- a/tests/Unit/AlgoliaEngineTest.php +++ b/tests/Unit/AlgoliaEngineTest.php @@ -3,11 +3,14 @@ namespace Laravel\Scout\Tests\Unit; use Algolia\AlgoliaSearch\SearchClient; +use Illuminate\Container\Container; use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Facades\Config; use Illuminate\Support\LazyCollection; use Laravel\Scout\Builder; +use Laravel\Scout\EngineManager; use Laravel\Scout\Engines\AlgoliaEngine; +use Laravel\Scout\Jobs\RemoveFromSearch; use Laravel\Scout\Tests\Fixtures\EmptySearchableModel; use Laravel\Scout\Tests\Fixtures\SearchableModel; use Laravel\Scout\Tests\Fixtures\SoftDeletedEmptySearchableModel; @@ -25,6 +28,7 @@ protected function setUp(): void protected function tearDown(): void { + Container::getInstance()->flush(); m::close(); } @@ -51,6 +55,59 @@ public function test_delete_removes_objects_to_index() $engine->delete(Collection::make([new SearchableModel(['id' => 1])])); } + public function test_delete_removes_objects_to_index_with_a_custom_search_key() + { + $client = m::mock(SearchClient::class); + $client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock(Indexes::class)); + $index->shouldReceive('deleteObjects')->once()->with(['my-algolia-key.5']); + + $engine = new AlgoliaEngine($client); + $engine->delete(Collection::make([new AlgoliaCustomKeySearchableModel(['id' => 5])])); + } + + public function test_delete_with_removeable_scout_collection_using_custom_search_key() + { + $job = new RemoveFromSearch(Collection::make([ + new AlgoliaCustomKeySearchableModel(['id' => 5]) + ])); + + $job = unserialize(serialize($job)); + + $client = m::mock(SearchClient::class); + $client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock(stdClass::class)); + $index->shouldReceive('deleteObjects')->once()->with(['my-algolia-key.5']); + + $engine = new AlgoliaEngine($client); + $engine->delete($job->models); + } + + public function test_remove_from_search_job_uses_custom_search_key() + { + $job = new RemoveFromSearch(Collection::make([ + new AlgoliaCustomKeySearchableModel(['id' => 5]) + ])); + + $job = unserialize(serialize($job)); + + Container::getInstance()->bind(EngineManager::class, function () { + $engine = m::mock(AlgoliaEngine::class); + + $engine->shouldReceive('delete')->once()->with(m::on(function ($collection) { + $keyName = ($model = $collection->first())->getUnqualifiedScoutKeyName(); + + return $model->getAttributes()[$keyName] === 'my-algolia-key.5'; + })); + + $manager = m::mock(EngineManager::class); + + $manager->shouldReceive('engine')->andReturn($engine); + + return $manager; + }); + + $job->handle(); + } + public function test_search_sends_correct_parameters_to_algolia() { $client = m::mock(SearchClient::class); From ce381f942d396c24b902c5dfed4292cd124358f0 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 09:17:43 -0400 Subject: [PATCH 10/21] Rename "$values" to "$keys" for clarity --- src/Engines/AlgoliaEngine.php | 4 ++-- src/Engines/MeiliSearchEngine.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Engines/AlgoliaEngine.php b/src/Engines/AlgoliaEngine.php index aea5acae..6fd359cf 100644 --- a/src/Engines/AlgoliaEngine.php +++ b/src/Engines/AlgoliaEngine.php @@ -89,11 +89,11 @@ public function delete($models) $index = $this->algolia->initIndex($models->first()->searchableAs()); - $values = $models instanceof RemoveableScoutCollection + $keys = $models instanceof RemoveableScoutCollection ? $models->pluck($models->first()->getUnqualifiedScoutKeyName()) : $models->map->getScoutKey(); - $index->deleteObjects($values->all()); + $index->deleteObjects($keys->all()); } /** diff --git a/src/Engines/MeiliSearchEngine.php b/src/Engines/MeiliSearchEngine.php index 099826e1..34226ceb 100644 --- a/src/Engines/MeiliSearchEngine.php +++ b/src/Engines/MeiliSearchEngine.php @@ -90,11 +90,11 @@ public function delete($models) $index = $this->meilisearch->index($models->first()->searchableAs()); - $values = $models instanceof RemoveableScoutCollection + $keys = $models instanceof RemoveableScoutCollection ? $models->pluck($models->first()->getUnqualifiedScoutKeyName()) : $models->map->getScoutKey(); - $index->deleteDocuments($values->all()); + $index->deleteDocuments($keys->all()); } /** From 8b9270f812e8de28e6371ecd5ecb20e61f491116 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 09:18:37 -0400 Subject: [PATCH 11/21] Spacing --- tests/Unit/RemoveableScoutCollectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/RemoveableScoutCollectionTest.php b/tests/Unit/RemoveableScoutCollectionTest.php index 408a42d4..2cecbdab 100644 --- a/tests/Unit/RemoveableScoutCollectionTest.php +++ b/tests/Unit/RemoveableScoutCollectionTest.php @@ -50,4 +50,4 @@ public function getScoutKey() { return 'custom-key.'.$this->getKey(); } -} \ No newline at end of file +} From e137aa4513526812be79b99e4d13f1d4477105ed Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 09:46:25 -0400 Subject: [PATCH 12/21] Remove unused imports --- src/Builder.php | 1 - src/Engines/MeiliSearchEngine.php | 1 - src/Jobs/RemoveFromSearch.php | 2 -- 3 files changed, 4 deletions(-) diff --git a/src/Builder.php b/src/Builder.php index 9bd89df8..f6ca515f 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -5,7 +5,6 @@ use Illuminate\Container\Container; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\Paginator; -use Illuminate\Support\Str; use Illuminate\Support\Traits\Macroable; use Laravel\Scout\Contracts\PaginatesEloquentModels; diff --git a/src/Engines/MeiliSearchEngine.php b/src/Engines/MeiliSearchEngine.php index 34226ceb..896fd478 100644 --- a/src/Engines/MeiliSearchEngine.php +++ b/src/Engines/MeiliSearchEngine.php @@ -3,7 +3,6 @@ namespace Laravel\Scout\Engines; use Illuminate\Support\LazyCollection; -use Illuminate\Support\Str; use Laravel\Scout\Builder; use Laravel\Scout\Jobs\RemoveableScoutCollection; use MeiliSearch\Client as MeiliSearchClient; diff --git a/src/Jobs/RemoveFromSearch.php b/src/Jobs/RemoveFromSearch.php index caceb16c..0d2f79e9 100644 --- a/src/Jobs/RemoveFromSearch.php +++ b/src/Jobs/RemoveFromSearch.php @@ -4,9 +4,7 @@ use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; -use Illuminate\Database\Eloquent\Collection as EloquentCollection; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Str; class RemoveFromSearch implements ShouldQueue { From d3557d21aa3ca50f3f9d2a8bcdcb3d5a0385702c Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 09:52:30 -0400 Subject: [PATCH 13/21] CS fixes --- src/Jobs/RemoveFromSearch.php | 2 +- src/Searchable.php | 2 +- tests/Unit/AlgoliaEngineTest.php | 4 ++-- tests/Unit/MeiliSearchEngineTest.php | 6 +++--- tests/Unit/RemoveableScoutCollectionTest.php | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Jobs/RemoveFromSearch.php b/src/Jobs/RemoveFromSearch.php index 0d2f79e9..99bb681a 100644 --- a/src/Jobs/RemoveFromSearch.php +++ b/src/Jobs/RemoveFromSearch.php @@ -61,7 +61,7 @@ protected function restoreCollection($value) $model->setKeyType( is_string($id) ? 'string' : 'int' )->forceFill([ - $model->getUnqualifiedScoutKeyName() => $id + $model->getUnqualifiedScoutKeyName() => $id, ]); }); }) diff --git a/src/Searchable.php b/src/Searchable.php index ad7089d1..1a9fd6ce 100644 --- a/src/Searchable.php +++ b/src/Searchable.php @@ -2,9 +2,9 @@ namespace Laravel\Scout; -use Illuminate\Support\Str; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Collection as BaseCollection; +use Illuminate\Support\Str; trait Searchable { diff --git a/tests/Unit/AlgoliaEngineTest.php b/tests/Unit/AlgoliaEngineTest.php index 119ed1b3..3ce27013 100644 --- a/tests/Unit/AlgoliaEngineTest.php +++ b/tests/Unit/AlgoliaEngineTest.php @@ -68,7 +68,7 @@ public function test_delete_removes_objects_to_index_with_a_custom_search_key() public function test_delete_with_removeable_scout_collection_using_custom_search_key() { $job = new RemoveFromSearch(Collection::make([ - new AlgoliaCustomKeySearchableModel(['id' => 5]) + new AlgoliaCustomKeySearchableModel(['id' => 5]), ])); $job = unserialize(serialize($job)); @@ -84,7 +84,7 @@ public function test_delete_with_removeable_scout_collection_using_custom_search public function test_remove_from_search_job_uses_custom_search_key() { $job = new RemoveFromSearch(Collection::make([ - new AlgoliaCustomKeySearchableModel(['id' => 5]) + new AlgoliaCustomKeySearchableModel(['id' => 5]), ])); $job = unserialize(serialize($job)); diff --git a/tests/Unit/MeiliSearchEngineTest.php b/tests/Unit/MeiliSearchEngineTest.php index 4ad26a94..33822fb5 100644 --- a/tests/Unit/MeiliSearchEngineTest.php +++ b/tests/Unit/MeiliSearchEngineTest.php @@ -72,7 +72,7 @@ public function test_delete_removes_objects_to_index_with_a_custom_search_key() public function test_delete_with_removeable_scout_collection_using_custom_search_key() { $job = new RemoveFromSearch(Collection::make([ - new MeiliSearchCustomKeySearchableModel(['id' => 5]) + new MeiliSearchCustomKeySearchableModel(['id' => 5]), ])); $job = unserialize(serialize($job)); @@ -88,7 +88,7 @@ public function test_delete_with_removeable_scout_collection_using_custom_search public function test_remove_from_search_job_uses_custom_search_key() { $job = new RemoveFromSearch(Collection::make([ - new MeiliSearchCustomKeySearchableModel(['id' => 5]) + new MeiliSearchCustomKeySearchableModel(['id' => 5]), ])); $job = unserialize(serialize($job)); @@ -369,7 +369,7 @@ public function test_a_model_is_indexed_with_a_custom_meilisearch_key() $client = m::mock(Client::class); $client->shouldReceive('index')->with('table')->andReturn($index = m::mock(Indexes::class)); $index->shouldReceive('addDocuments')->once()->with([[ - 'id' => 'my-meilisearch-key.5' + 'id' => 'my-meilisearch-key.5', ]], 'id'); $engine = new MeiliSearchEngine($client); diff --git a/tests/Unit/RemoveableScoutCollectionTest.php b/tests/Unit/RemoveableScoutCollectionTest.php index 2cecbdab..1acef29c 100644 --- a/tests/Unit/RemoveableScoutCollectionTest.php +++ b/tests/Unit/RemoveableScoutCollectionTest.php @@ -5,8 +5,8 @@ use Illuminate\Support\Facades\Config; use Laravel\Scout\Jobs\RemoveableScoutCollection; use Laravel\Scout\Tests\Fixtures\SearchableModel; -use PHPUnit\Framework\TestCase; use Mockery as m; +use PHPUnit\Framework\TestCase; class RemoveableScoutCollectionTest extends TestCase { @@ -23,7 +23,7 @@ public function test_get_queuable_ids() new SearchableModel(['id' => 2]), ]); - $this->assertEquals([1,2], $collection->getQueueableIds()); + $this->assertEquals([1, 2], $collection->getQueueableIds()); } public function test_get_queuable_ids_resolves_custom_scout_keys() From 1934e76b281a1c14ac2b502d86acb64a4bc615b4 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 09:54:34 -0400 Subject: [PATCH 14/21] Comment clarification --- src/Jobs/RemoveFromSearch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jobs/RemoveFromSearch.php b/src/Jobs/RemoveFromSearch.php index 99bb681a..9ad6b474 100644 --- a/src/Jobs/RemoveFromSearch.php +++ b/src/Jobs/RemoveFromSearch.php @@ -57,7 +57,7 @@ protected function restoreCollection($value) return tap(new $value->class, function ($model) use ($id) { // The scout key may not be an integer. In this case, // we will force a key type of string so it is not - // cast when retrieving it from the model. + // cast when retrieving it from the faux model. $model->setKeyType( is_string($id) ? 'string' : 'int' )->forceFill([ From a8a36c965b4f1acc44494d99e81390531ede0dc5 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 12:10:34 -0400 Subject: [PATCH 15/21] Remove use of `getUnqualifiedScoutKeyName()` in favour of `getScoutKeyName()` --- src/Engines/AlgoliaEngine.php | 2 +- src/Engines/MeiliSearchEngine.php | 4 ++-- src/Searchable.php | 12 +----------- tests/Unit/AlgoliaEngineTest.php | 2 +- tests/Unit/MeiliSearchEngineTest.php | 4 ++-- 5 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/Engines/AlgoliaEngine.php b/src/Engines/AlgoliaEngine.php index 6fd359cf..4dea0733 100644 --- a/src/Engines/AlgoliaEngine.php +++ b/src/Engines/AlgoliaEngine.php @@ -90,7 +90,7 @@ public function delete($models) $index = $this->algolia->initIndex($models->first()->searchableAs()); $keys = $models instanceof RemoveableScoutCollection - ? $models->pluck($models->first()->getUnqualifiedScoutKeyName()) + ? $models->pluck($models->first()->getScoutKeyName()) : $models->map->getScoutKey(); $index->deleteObjects($keys->all()); diff --git a/src/Engines/MeiliSearchEngine.php b/src/Engines/MeiliSearchEngine.php index 205e0013..2e5e25cb 100644 --- a/src/Engines/MeiliSearchEngine.php +++ b/src/Engines/MeiliSearchEngine.php @@ -90,7 +90,7 @@ public function delete($models) $index = $this->meilisearch->index($models->first()->searchableAs()); $keys = $models instanceof RemoveableScoutCollection - ? $models->pluck($models->first()->getUnqualifiedScoutKeyName()) + ? $models->pluck($models->first()->getScoutKeyName()) : $models->map->getScoutKey(); $index->deleteDocuments($keys->all()); @@ -248,7 +248,7 @@ public function mapIdsFrom($results, $key) */ public function keys(Builder $builder) { - $scoutKey = $builder->model->getUnqualifiedScoutKeyName(); + $scoutKey = $builder->model->getScoutKeyName(); return $this->mapIdsFrom($this->search($builder), $scoutKey); } diff --git a/src/Searchable.php b/src/Searchable.php index a7f9f467..e39efdd7 100644 --- a/src/Searchable.php +++ b/src/Searchable.php @@ -391,17 +391,7 @@ public function getScoutKeyName() { return $this->getKeyName(); } - - /** - * Get the unqualified Scout key name. - * - * @return string - */ - public function getUnqualifiedScoutKeyName() - { - return Str::afterLast($this->getScoutKeyName(), '.'); - } - + /** * Determine if the current class should use soft deletes with searching. * diff --git a/tests/Unit/AlgoliaEngineTest.php b/tests/Unit/AlgoliaEngineTest.php index 3ce27013..4138e78d 100644 --- a/tests/Unit/AlgoliaEngineTest.php +++ b/tests/Unit/AlgoliaEngineTest.php @@ -93,7 +93,7 @@ public function test_remove_from_search_job_uses_custom_search_key() $engine = m::mock(AlgoliaEngine::class); $engine->shouldReceive('delete')->once()->with(m::on(function ($collection) { - $keyName = ($model = $collection->first())->getUnqualifiedScoutKeyName(); + $keyName = ($model = $collection->first())->getScoutKeyName(); return $model->getAttributes()[$keyName] === 'my-algolia-key.5'; })); diff --git a/tests/Unit/MeiliSearchEngineTest.php b/tests/Unit/MeiliSearchEngineTest.php index 00ace846..2d693fa3 100644 --- a/tests/Unit/MeiliSearchEngineTest.php +++ b/tests/Unit/MeiliSearchEngineTest.php @@ -97,7 +97,7 @@ public function test_remove_from_search_job_uses_custom_search_key() $engine = m::mock(MeiliSearchEngine::class); $engine->shouldReceive('delete')->once()->with(m::on(function ($collection) { - $keyName = ($model = $collection->first())->getUnqualifiedScoutKeyName(); + $keyName = ($model = $collection->first())->getScoutKeyName(); return $model->getAttributes()[$keyName] === 'my-meilisearch-key.5'; })); @@ -240,7 +240,7 @@ public function test_returns_primary_keys_when_custom_array_order_present() $builder = m::mock(Builder::class); $model = m::mock(stdClass::class); - $model->shouldReceive(['getUnqualifiedScoutKeyName' => 'custom_key']); + $model->shouldReceive(['getScoutKeyName' => 'custom_key']); $builder->model = $model; $engine->shouldReceive('keys')->passthru(); From 6e32b53d867af4997774932b6f45c87caf4d06cf Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 12:14:00 -0400 Subject: [PATCH 16/21] Revert change of scout key extraction --- src/Engines/MeiliSearchEngine.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Engines/MeiliSearchEngine.php b/src/Engines/MeiliSearchEngine.php index 2e5e25cb..f247899a 100644 --- a/src/Engines/MeiliSearchEngine.php +++ b/src/Engines/MeiliSearchEngine.php @@ -3,6 +3,7 @@ namespace Laravel\Scout\Engines; use Illuminate\Support\LazyCollection; +use Illuminate\Support\Str; use Laravel\Scout\Builder; use Laravel\Scout\Jobs\RemoveableScoutCollection; use MeiliSearch\Client as MeiliSearchClient; @@ -248,7 +249,7 @@ public function mapIdsFrom($results, $key) */ public function keys(Builder $builder) { - $scoutKey = $builder->model->getScoutKeyName(); + $scoutKey = Str::afterLast($builder->model->getScoutKeyName(), '.'); return $this->mapIdsFrom($this->search($builder), $scoutKey); } From 1ffa9fc9d603d365c3f526d4b6c88533e1e1b4eb Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 12:19:33 -0400 Subject: [PATCH 17/21] Revert to prefixed key to ensure Str::afterLast is used --- tests/Unit/MeiliSearchEngineTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/MeiliSearchEngineTest.php b/tests/Unit/MeiliSearchEngineTest.php index 2d693fa3..ebfbf4bf 100644 --- a/tests/Unit/MeiliSearchEngineTest.php +++ b/tests/Unit/MeiliSearchEngineTest.php @@ -240,7 +240,7 @@ public function test_returns_primary_keys_when_custom_array_order_present() $builder = m::mock(Builder::class); $model = m::mock(stdClass::class); - $model->shouldReceive(['getScoutKeyName' => 'custom_key']); + $model->shouldReceive(['getScoutKeyName' => 'table.custom_key']); $builder->model = $model; $engine->shouldReceive('keys')->passthru(); From f0f33510d1cdc3d7deadc0f9156075f811f0bd03 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 30 Sep 2022 12:20:16 -0400 Subject: [PATCH 18/21] CS Fixes --- src/Jobs/RemoveFromSearch.php | 2 +- src/Searchable.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Jobs/RemoveFromSearch.php b/src/Jobs/RemoveFromSearch.php index 0f4d3d23..5302b8da 100644 --- a/src/Jobs/RemoveFromSearch.php +++ b/src/Jobs/RemoveFromSearch.php @@ -61,7 +61,7 @@ protected function restoreCollection($value) $model->setKeyType( is_string($id) ? 'string' : 'int' )->forceFill([ - $model->getScoutKeyName() => $id + $model->getScoutKeyName() => $id, ]); }); }) diff --git a/src/Searchable.php b/src/Searchable.php index e39efdd7..d873aacc 100644 --- a/src/Searchable.php +++ b/src/Searchable.php @@ -4,7 +4,6 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Collection as BaseCollection; -use Illuminate\Support\Str; trait Searchable { @@ -391,7 +390,7 @@ public function getScoutKeyName() { return $this->getKeyName(); } - + /** * Determine if the current class should use soft deletes with searching. * From f3513953cdd6aa6e4ea87ce4fc510a4161a3d77f Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Wed, 7 Dec 2022 18:29:08 -0500 Subject: [PATCH 19/21] Update CHANGELOG.md --- CHANGELOG.md | 178 +++++++++++++++++++++++++-------------------------- 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e7cef70..067cb028 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,98 +6,98 @@ ### Added -- Support Meilisearch index settings by @driesvints in https://github.com/laravel/scout/pull/669 +- Support Meilisearch index settings by @driesvints in https://github.com/laravel/scout/pull/669 ## [v9.4.12](https://github.com/laravel/scout/compare/v9.4.11...v9.4.12) - 2022-10-04 ### Fixed -- Fix custom scout keys not being utilized when deleting from queue by @stevebauman in https://github.com/laravel/scout/pull/656 +- Fix custom scout keys not being utilized when deleting from queue by @stevebauman in https://github.com/laravel/scout/pull/656 ## [v9.4.11](https://github.com/laravel/scout/compare/v9.4.10...v9.4.11) - 2022-09-27 ### Fixed -- Use scout key when mapping keys from search results by @flexchar in https://github.com/laravel/scout/pull/652 +- Use scout key when mapping keys from search results by @flexchar in https://github.com/laravel/scout/pull/652 ## [v9.4.10](https://github.com/laravel/scout/compare/v9.4.9...v9.4.10) - 2022-07-19 ### Fixed -- Return collection by @driesvints in https://github.com/laravel/scout/pull/635 +- Return collection by @driesvints in https://github.com/laravel/scout/pull/635 ## [v9.4.9](https://github.com/laravel/scout/compare/v9.4.8...v9.4.9) - 2022-05-05 ### Fixed -- Apply `limit` on `DatabaseEngine` before applying additional constraints by @crynobone in https://github.com/laravel/scout/pull/621 +- Apply `limit` on `DatabaseEngine` before applying additional constraints by @crynobone in https://github.com/laravel/scout/pull/621 ## [v9.4.8](https://github.com/laravel/scout/compare/v9.4.7...v9.4.8) - 2022-05-03 ### Changed -- Add limit to database engine by @keithbrink in https://github.com/laravel/scout/pull/619 +- Add limit to database engine by @keithbrink in https://github.com/laravel/scout/pull/619 ## [v9.4.7](https://github.com/laravel/scout/compare/v9.4.6...v9.4.7) - 2022-04-06 ### Fixed -- Fixed access to undefined key by @den1n in https://github.com/laravel/scout/pull/612 +- Fixed access to undefined key by @den1n in https://github.com/laravel/scout/pull/612 ## [v9.4.6](https://github.com/laravel/scout/compare/v9.4.5...v9.4.6) - 2022-03-29 ### Changed -- Added the ability to pass an array of options to full-text search. by @den1n in https://github.com/laravel/scout/pull/606 -- Update suggested SDK versions of Algolia and Meilisearch by @mmachatschek in https://github.com/laravel/scout/pull/608 +- Added the ability to pass an array of options to full-text search. by @den1n in https://github.com/laravel/scout/pull/606 +- Update suggested SDK versions of Algolia and Meilisearch by @mmachatschek in https://github.com/laravel/scout/pull/608 ## [v9.4.5](https://github.com/laravel/scout/compare/v9.4.4...v9.4.5) - 2022-02-22 ### Changed -- Remove redundant `return` key like for all `when` methods for databas… by @siarheipashkevich in https://github.com/laravel/scout/pull/592 +- Remove redundant `return` key like for all `when` methods for databas… by @siarheipashkevich in https://github.com/laravel/scout/pull/592 ### Fixed -- Implements Meilisearch sort on paginate by @mrABR in https://github.com/laravel/scout/pull/587 -- Remove default order by model key desc in database engine when full-text index is used by @smknstd in https://github.com/laravel/scout/pull/590 -- Call queryCallback in DatabaseEngine by @Alanaktion in https://github.com/laravel/scout/pull/591 +- Implements Meilisearch sort on paginate by @mrABR in https://github.com/laravel/scout/pull/587 +- Remove default order by model key desc in database engine when full-text index is used by @smknstd in https://github.com/laravel/scout/pull/590 +- Call queryCallback in DatabaseEngine by @Alanaktion in https://github.com/laravel/scout/pull/591 ## [v9.4.4](https://github.com/laravel/scout/compare/v9.4.3...v9.4.4) - 2022-02-15 ### Fixed -- Fix collection engine `mapIds` bug by @amir9480 in https://github.com/laravel/scout/pull/585 +- Fix collection engine `mapIds` bug by @amir9480 in https://github.com/laravel/scout/pull/585 ## [v9.4.3](https://github.com/laravel/scout/compare/v9.4.2...v9.4.3) - 2022-02-08 ### Fixed -- Skip adding search constraints with empty search on DatabaseEngine ([#582](https://github.com/laravel/scout/pull/582)) +- Skip adding search constraints with empty search on DatabaseEngine ([#582](https://github.com/laravel/scout/pull/582)) ## [v9.4.2 (2022-01-18)](https://github.com/laravel/scout/compare/v9.4.1...v9.4.2) ### Added -- Add sorting for Meilisearch ([#537](https://github.com/laravel/scout/pull/537)) +- Add sorting for Meilisearch ([#537](https://github.com/laravel/scout/pull/537)) ## [v9.4.1 (2022-01-14)](https://github.com/laravel/scout/compare/v9.4.0...v9.4.1) ### Fixed -- Fix return for `paginateRaw` ([#574](https://github.com/laravel/scout/pull/574)) +- Fix return for `paginateRaw` ([#574](https://github.com/laravel/scout/pull/574)) ## [v9.4.0 (2022-01-12)](https://github.com/laravel/scout/compare/v9.3.4...v9.4.0) ### Added -- Add a DatabaseEngine ([#564](https://github.com/laravel/scout/pull/564)) +- Add a DatabaseEngine ([#564](https://github.com/laravel/scout/pull/564)) ### Changed -- Optimize whereIn to use whereIntegerInRaw when primaryKey is integer ([#568](https://github.com/laravel/scout/pull/568)) -- Add limit to collection engine ([#569](https://github.com/laravel/scout/pull/569)) -- Laravel 9 support ([#571](https://github.com/laravel/scout/pull/571)) +- Optimize whereIn to use whereIntegerInRaw when primaryKey is integer ([#568](https://github.com/laravel/scout/pull/568)) +- Add limit to collection engine ([#569](https://github.com/laravel/scout/pull/569)) +- Laravel 9 support ([#571](https://github.com/laravel/scout/pull/571)) ## [v9.3.4 (2021-12-23)](https://github.com/laravel/scout/compare/v9.3.2...v9.3.4) @@ -107,321 +107,321 @@ No significant changes. ### Fixed -- Fix issues for users providing searchable array without primary key ([#547](https://github.com/laravel/scout/pull/547)) +- Fix issues for users providing searchable array without primary key ([#547](https://github.com/laravel/scout/pull/547)) ## [v9.3.1 (2021-10-12)](https://github.com/laravel/scout/compare/v9.3.0...v9.3.1) ### Fixed -- Return correct output of mapIds method for MeiliSearch ([#538](https://github.com/laravel/scout/pull/538)) +- Return correct output of mapIds method for MeiliSearch ([#538](https://github.com/laravel/scout/pull/538)) ## [v9.3.0 (2021-10-05)](https://github.com/laravel/scout/compare/v9.2.10...v9.3.0) ### Added -- Add simplePaginateRaw query ([#534](https://github.com/laravel/scout/pull/534)) +- Add simplePaginateRaw query ([#534](https://github.com/laravel/scout/pull/534)) ## [v9.2.10 (2021-09-28)](https://github.com/laravel/scout/compare/v9.2.9...v9.2.10) ### Changed -- Collection Engine: add support for non-scalar values ([#528](https://github.com/laravel/scout/pull/528)) +- Collection Engine: add support for non-scalar values ([#528](https://github.com/laravel/scout/pull/528)) ### Fixed -- Support boolean filters ([#524](https://github.com/laravel/scout/pull/524)) +- Support boolean filters ([#524](https://github.com/laravel/scout/pull/524)) ## [v9.2.9 (2021-09-14)](https://github.com/laravel/scout/compare/v9.2.8...v9.2.9) ### Fixed -- Searching on custom searchable data when using collection driver ([#521](https://github.com/laravel/scout/pull/521)) +- Searching on custom searchable data when using collection driver ([#521](https://github.com/laravel/scout/pull/521)) ## [v9.2.8 (2021-08-31)](https://github.com/laravel/scout/compare/v9.2.7...v9.2.8) ### Changed -- Add the ability to omit the search argument in the `CollectionEngine` ([#515](https://github.com/laravel/scout/pull/515)) +- Add the ability to omit the search argument in the `CollectionEngine` ([#515](https://github.com/laravel/scout/pull/515)) ### Fixed -- Update meilisearch-sdk version to v0.19.0 ([#511](https://github.com/laravel/scout/pull/511)) -- Check for meilisearch-php 0.19.0 instead ([#513](https://github.com/laravel/scout/pull/513)) +- Update meilisearch-sdk version to v0.19.0 ([#511](https://github.com/laravel/scout/pull/511)) +- Check for meilisearch-php 0.19.0 instead ([#513](https://github.com/laravel/scout/pull/513)) ## [v9.2.7 (2021-08-24)](https://github.com/laravel/scout/compare/v9.2.6...v9.2.7) ### Changed -- Support rename of filters to filter in meilisearch 0.21.x ([#510](https://github.com/laravel/scout/pull/510)) +- Support rename of filters to filter in meilisearch 0.21.x ([#510](https://github.com/laravel/scout/pull/510)) ## [v9.2.6 (2021-08-17)](https://github.com/laravel/scout/compare/v9.2.5...v9.2.6) ### Fixed -- Fixed non string columns breaking model filter with collection driver ([#507](https://github.com/laravel/scout/pull/507)) +- Fixed non string columns breaking model filter with collection driver ([#507](https://github.com/laravel/scout/pull/507)) ## [v9.2.5 (2021-08-10)](https://github.com/laravel/scout/compare/v9.2.4...v9.2.5) ### Fixed -- `HasManyThrough::macro('unsearchable')` fix ([#505](https://github.com/laravel/scout/pull/505)) +- `HasManyThrough::macro('unsearchable')` fix ([#505](https://github.com/laravel/scout/pull/505)) ## [v9.2.4 (2021-08-03)](https://github.com/laravel/scout/compare/v9.2.3...v9.2.4) ### Changed -- Timeout options for algolia client ([#501](https://github.com/laravel/scout/pull/501)) +- Timeout options for algolia client ([#501](https://github.com/laravel/scout/pull/501)) ### Fixed -- Fix meilisearch where in ([#498](https://github.com/laravel/scout/pull/498)) +- Fix meilisearch where in ([#498](https://github.com/laravel/scout/pull/498)) ## [v9.2.3 (2021-07-13)](https://github.com/laravel/scout/compare/v9.2.2...v9.2.3) ### Changed -- Filter on sensitive attributes ([#491](https://github.com/laravel/scout/pull/491), [1dfde65](https://github.com/laravel/scout/commit/1dfde65d4d9fa78512c68020f6fa05ee0f19eae8)) +- Filter on sensitive attributes ([#491](https://github.com/laravel/scout/pull/491), [1dfde65](https://github.com/laravel/scout/commit/1dfde65d4d9fa78512c68020f6fa05ee0f19eae8)) ## [v9.2.2 (2021-07-06)](https://github.com/laravel/scout/compare/v9.2.1...v9.2.2) ### Changed -- Improve observer strategy ([#490](https://github.com/laravel/scout/pull/490), [19cff04](https://github.com/laravel/scout/commit/19cff04e97f3fbaf67bf2bbe68a5d4daba6ba8b1)) -- Downcase attribute and query for case-insensitive search ([#493](https://github.com/laravel/scout/pull/493)) -- Use numeric check ([996256a](https://github.com/laravel/scout/commit/996256abf3b59db3e8dd3b428e027c0c1b2c37d3)) -- Custom callback support on collection engine ([7da9dd6](https://github.com/laravel/scout/commit/7da9dd69df7e63d48c53f5e92fa777b2b67d352e)) +- Improve observer strategy ([#490](https://github.com/laravel/scout/pull/490), [19cff04](https://github.com/laravel/scout/commit/19cff04e97f3fbaf67bf2bbe68a5d4daba6ba8b1)) +- Downcase attribute and query for case-insensitive search ([#493](https://github.com/laravel/scout/pull/493)) +- Use numeric check ([996256a](https://github.com/laravel/scout/commit/996256abf3b59db3e8dd3b428e027c0c1b2c37d3)) +- Custom callback support on collection engine ([7da9dd6](https://github.com/laravel/scout/commit/7da9dd69df7e63d48c53f5e92fa777b2b67d352e)) ## [v9.2.1 (2021-06-29)](https://github.com/laravel/scout/compare/v9.2.0...v9.2.1) ### Added -- Add `whereIn` support ([2b1dd75](https://github.com/laravel/scout/commit/2b1dd75adb533d71d3430ea91cd061bfe2fa0f32)) +- Add `whereIn` support ([2b1dd75](https://github.com/laravel/scout/commit/2b1dd75adb533d71d3430ea91cd061bfe2fa0f32)) ### Fixed -- Filter on should be searchable ([ad60f5b](https://github.com/laravel/scout/commit/ad60f5bf38b735e8a4178039515f4e30f44126b6)) -- Handle soft deletes ([f04927d](https://github.com/laravel/scout/commit/f04927d21bf48b79040189b41464e33b6d26dd1d), [b95af2e](https://github.com/laravel/scout/commit/b95af2e7a231f4403c7add1a7eba96cac1b415fb), [31073e4](https://github.com/laravel/scout/commit/31073e4ad5c0977a9a088b8793bba0e2c3d29c5d)) -- Fix pagination ([733eda3](https://github.com/laravel/scout/commit/733eda3d44140f87e235805531cd4c8c9ac04b59)) +- Filter on should be searchable ([ad60f5b](https://github.com/laravel/scout/commit/ad60f5bf38b735e8a4178039515f4e30f44126b6)) +- Handle soft deletes ([f04927d](https://github.com/laravel/scout/commit/f04927d21bf48b79040189b41464e33b6d26dd1d), [b95af2e](https://github.com/laravel/scout/commit/b95af2e7a231f4403c7add1a7eba96cac1b415fb), [31073e4](https://github.com/laravel/scout/commit/31073e4ad5c0977a9a088b8793bba0e2c3d29c5d)) +- Fix pagination ([733eda3](https://github.com/laravel/scout/commit/733eda3d44140f87e235805531cd4c8c9ac04b59)) ## [v9.2.0 (2021-06-29)](https://github.com/laravel/scout/compare/v9.1.2...v9.2.0) ### Added -- Collection Engine ([#488](https://github.com/laravel/scout/pull/488)) +- Collection Engine ([#488](https://github.com/laravel/scout/pull/488)) ## [v9.1.2 (2021-06-15)](https://github.com/laravel/scout/compare/v9.1.1...v9.1.2) ### Fixed -- Fix removing queued models with custom Scout keys ([#480](https://github.com/laravel/scout/pull/480)) -- Re-query scout engine when paginate results contains insufficient keys to generate proper pagination count query ([#483](https://github.com/laravel/scout/pull/483)) +- Fix removing queued models with custom Scout keys ([#480](https://github.com/laravel/scout/pull/480)) +- Re-query scout engine when paginate results contains insufficient keys to generate proper pagination count query ([#483](https://github.com/laravel/scout/pull/483)) ## [v9.1.1 (2021-06-08)](https://github.com/laravel/scout/compare/v9.1.0...v9.1.1) ### Changed -- Overridable jobs ([#476](https://github.com/laravel/scout/pull/476)) +- Overridable jobs ([#476](https://github.com/laravel/scout/pull/476)) ## [v9.1.0 (2021-05-13)](https://github.com/laravel/scout/compare/v9.0.0...v9.1.0) ### Added -- Use queued job for "unsearching" when Scout queue is enabled ([#471](https://github.com/laravel/scout/pull/471)) +- Use queued job for "unsearching" when Scout queue is enabled ([#471](https://github.com/laravel/scout/pull/471)) ### Changed -- Remove useless variable in `simplePaginate` ([#472](https://github.com/laravel/scout/pull/472)) +- Remove useless variable in `simplePaginate` ([#472](https://github.com/laravel/scout/pull/472)) ## [v9.0.0 (2021-04-27)](https://github.com/laravel/scout/compare/v8.6.1...v9.0.0) ### Added -- Support MeiliSearch Engine ([#455](https://github.com/laravel/scout/pull/455), [#457](https://github.com/laravel/scout/pull/457)) -- Add support for cursor and LazyCollection on scout ([#439](https://github.com/laravel/scout/pull/439), [1ebcd0d](https://github.com/laravel/scout/commit/1ebcd0d11185d43cea18e9b774b2926314311e41), [#470](https://github.com/laravel/scout/pull/470)) +- Support MeiliSearch Engine ([#455](https://github.com/laravel/scout/pull/455), [#457](https://github.com/laravel/scout/pull/457)) +- Add support for cursor and LazyCollection on scout ([#439](https://github.com/laravel/scout/pull/439), [1ebcd0d](https://github.com/laravel/scout/commit/1ebcd0d11185d43cea18e9b774b2926314311e41), [#470](https://github.com/laravel/scout/pull/470)) ### Changed -- Drop support for old Laravel versions and PHP 7.2 ([#459](https://github.com/laravel/scout/pull/459)) +- Drop support for old Laravel versions and PHP 7.2 ([#459](https://github.com/laravel/scout/pull/459)) ### Fixed -- Fixes pagination count when `Laravel\Scout\Builder` contains custom query callback ([#469](https://github.com/laravel/scout/pull/469)) +- Fixes pagination count when `Laravel\Scout\Builder` contains custom query callback ([#469](https://github.com/laravel/scout/pull/469)) ## [v8.6.1 (2021-04-06)](https://github.com/laravel/scout/compare/v8.6.0...v8.6.1) ### Changed -- Move booting of services ([#453](https://github.com/laravel/scout/pull/453)) -- Add reset method ([fb8ce0c](https://github.com/laravel/scout/commit/fb8ce0c3a0ea33fc67be9a0916bf049a7e86bd54)) +- Move booting of services ([#453](https://github.com/laravel/scout/pull/453)) +- Add reset method ([fb8ce0c](https://github.com/laravel/scout/commit/fb8ce0c3a0ea33fc67be9a0916bf049a7e86bd54)) ## [v8.6.0 (2021-01-19)](https://github.com/laravel/scout/compare/v8.5.4...v8.6.0) ### Added -- Add ability to use simplePaginate ([#443](https://github.com/laravel/scout/pull/443)) +- Add ability to use simplePaginate ([#443](https://github.com/laravel/scout/pull/443)) ## [v8.5.4 (2021-01-12)](https://github.com/laravel/scout/compare/v8.5.3...v8.5.4) ### Changed -- Use the Config facade instead ([#442](https://github.com/laravel/scout/pull/442)) +- Use the Config facade instead ([#442](https://github.com/laravel/scout/pull/442)) ## [v8.5.3 (2021-01-05)](https://github.com/laravel/scout/compare/v8.5.2...v8.5.3) ### Fixed -- Allow running observer callbacks after database transactions have committed ([#440](https://github.com/laravel/scout/pull/440), [56ea20d](https://github.com/laravel/scout/commit/56ea20d8e46cc9cd03d04cbdd071e4deb94e7f26)) +- Allow running observer callbacks after database transactions have committed ([#440](https://github.com/laravel/scout/pull/440), [56ea20d](https://github.com/laravel/scout/commit/56ea20d8e46cc9cd03d04cbdd071e4deb94e7f26)) ## [v8.5.2 (2020-12-30)](https://github.com/laravel/scout/compare/v8.5.1...v8.5.2) ### Changed -- Revert `$afterCommit` property ([ece6758](https://github.com/laravel/scout/commit/ece6758b82c51ff7f5e011f243a7c6b33711a847)) +- Revert `$afterCommit` property ([ece6758](https://github.com/laravel/scout/commit/ece6758b82c51ff7f5e011f243a7c6b33711a847)) ## [v8.5.1 (2020-12-22)](https://github.com/laravel/scout/compare/v8.5.0...v8.5.1) ### Changed -- Run observer callbacks after database transactions have committed ([#436](https://github.com/laravel/scout/pull/436)) +- Run observer callbacks after database transactions have committed ([#436](https://github.com/laravel/scout/pull/436)) ## [v8.5.0 (2020-12-10)](https://github.com/laravel/scout/compare/v8.4.0...v8.5.0) ### Added -- PHP 8 Support ([#425](https://github.com/laravel/scout/pull/425)) +- PHP 8 Support ([#425](https://github.com/laravel/scout/pull/425)) ## [v8.4.0 (2020-10-20)](https://github.com/laravel/scout/compare/v8.3.1...v8.4.0) ### Added -- Add `makeAllSearchableUsing` ([bf8585e](https://github.com/laravel/scout/commit/bf8585eaff9204d23602f9c064b7e3cc074212e2)) +- Add `makeAllSearchableUsing` ([bf8585e](https://github.com/laravel/scout/commit/bf8585eaff9204d23602f9c064b7e3cc074212e2)) ## [v8.3.1 (2020-09-01)](https://github.com/laravel/scout/compare/v8.3.0...v8.3.1) ### Fixed -- Fix HasManyThrough relationships ([#416](https://github.com/laravel/scout/pull/416)) +- Fix HasManyThrough relationships ([#416](https://github.com/laravel/scout/pull/416)) ## [v8.3.0 (2020-08-25)](https://github.com/laravel/scout/compare/v8.2.1...v8.3.0) ### Added -- Laravel 8 support ([#415](https://github.com/laravel/scout/pull/415)) +- Laravel 8 support ([#415](https://github.com/laravel/scout/pull/415)) ### Changed -- Update builder class pagination methods to resolve LengthAwarePaginator using container ([#413](https://github.com/laravel/scout/pull/413)) +- Update builder class pagination methods to resolve LengthAwarePaginator using container ([#413](https://github.com/laravel/scout/pull/413)) ## [v8.2.1 (2020-08-06)](https://github.com/laravel/scout/compare/v8.2.0...v8.2.1) ### Fixed -- Fix undefined `$user` variable bug ([e751cf4](https://github.com/laravel/scout/commit/e751cf4669ecab2fce887265280d1dfd29075aef)) +- Fix undefined `$user` variable bug ([e751cf4](https://github.com/laravel/scout/commit/e751cf4669ecab2fce887265280d1dfd29075aef)) ## [v8.2.0 (2020-08-04)](https://github.com/laravel/scout/compare/v8.1.0...v8.2.0) ### Added -- Identifying users ([#411](https://github.com/laravel/scout/pull/411), [fe28ab2](https://github.com/laravel/scout/commit/fe28ab26bf1e5c9c3b46f2535bea746b69fa6fb1)) +- Identifying users ([#411](https://github.com/laravel/scout/pull/411), [fe28ab2](https://github.com/laravel/scout/commit/fe28ab26bf1e5c9c3b46f2535bea746b69fa6fb1)) ## [v8.1.0 (2020-07-14)](https://github.com/laravel/scout/compare/v8.0.1...v8.1.0) ### Added -- Optional param for chunk size on `scout:import` ([#407](https://github.com/laravel/scout/pull/407)) +- Optional param for chunk size on `scout:import` ([#407](https://github.com/laravel/scout/pull/407)) ## [v8.0.1 (2020-04-21)](https://github.com/laravel/scout/compare/v8.0.0...v8.0.1) ### Fixed -- Merge default scout configs ([#402](https://github.com/laravel/scout/pull/402)) +- Merge default scout configs ([#402](https://github.com/laravel/scout/pull/402)) ## [v8.0.0 (2020-03-03)](https://github.com/laravel/scout/compare/v7.2.1...v8.0.0) ### Changed -- Use chunkById instead of chunk ([#360](https://github.com/laravel/scout/pull/360)) -- Drop support for Laravel 5.x -- Drop support for PHP 7.1 +- Use chunkById instead of chunk ([#360](https://github.com/laravel/scout/pull/360)) +- Drop support for Laravel 5.x +- Drop support for PHP 7.1 ## [v7.2.1 (2019-09-24)](https://github.com/laravel/scout/compare/v7.2.0...v7.2.1) ### Fixed -- Proper version ([44c8924](https://github.com/laravel/scout/commit/44c8924815aab8dbbb1388bbd468e67f398ff3ef)) +- Proper version ([44c8924](https://github.com/laravel/scout/commit/44c8924815aab8dbbb1388bbd468e67f398ff3ef)) ## [v7.2.0 (2019-09-24)](https://github.com/laravel/scout/compare/v7.1.3...v7.2.0) ### Added -- Add `__call()` method to AlgoliaEngine ([#384](https://github.com/laravel/scout/pull/384)) +- Add `__call()` method to AlgoliaEngine ([#384](https://github.com/laravel/scout/pull/384)) ## [v7.1.3 (2019-07-30)](https://github.com/laravel/scout/compare/v7.1.2...v7.1.3) ### Changed -- Updated version constraints for Laravel 6 ([b31e612](https://github.com/laravel/scout/commit/b31e6123776ae7f5006dd8e12701e3d661c3db0d)) +- Updated version constraints for Laravel 6 ([b31e612](https://github.com/laravel/scout/commit/b31e6123776ae7f5006dd8e12701e3d661c3db0d)) ## [v7.1.2 (2019-04-30)](https://github.com/laravel/scout/compare/v7.1.1...v7.1.2) ### Fixed -- Calling `values()` on sorted collection to reset the array keys ([#372](https://github.com/laravel/scout/pull/372)) +- Calling `values()` on sorted collection to reset the array keys ([#372](https://github.com/laravel/scout/pull/372)) ## [v7.1.1 (2019-04-02)](https://github.com/laravel/scout/compare/v7.1.0...v7.1.1) ### Changed -- Remove support for PHP 7.0 ([217c2ee](https://github.com/laravel/scout/commit/217c2eebacb2fb242083102222428fa492b637bd)) +- Remove support for PHP 7.0 ([217c2ee](https://github.com/laravel/scout/commit/217c2eebacb2fb242083102222428fa492b637bd)) ### Fixed -- Fix engine results order ([#369](https://github.com/laravel/scout/pull/369), [bde4969](https://github.com/laravel/scout/commit/bde49694850e1c025bea7a77f3bd422862c7ab87)) -- Fix empty update with soft delete ([#370](https://github.com/laravel/scout/pull/370)) +- Fix engine results order ([#369](https://github.com/laravel/scout/pull/369), [bde4969](https://github.com/laravel/scout/commit/bde49694850e1c025bea7a77f3bd422862c7ab87)) +- Fix empty update with soft delete ([#370](https://github.com/laravel/scout/pull/370)) ## [v7.1.0 (2019-02-14)](https://github.com/laravel/scout/compare/v7.0.0...v7.1.0) ### Added -- Added support for Laravel 5.8 ([694d83b](https://github.com/laravel/scout/commit/694d83bfc735cc2147c5ad57b034ea89a7893e08)) +- Added support for Laravel 5.8 ([694d83b](https://github.com/laravel/scout/commit/694d83bfc735cc2147c5ad57b034ea89a7893e08)) ## [v7.0.0 (2019-02-08)](https://github.com/laravel/scout/compare/v6.1.3...v7.0.0) ### Changed -- Upgraded Algolia API client to v2 ([#349](https://github.com/laravel/scout/pull/349), [#353](https://github.com/laravel/scout/pull/353)) +- Upgraded Algolia API client to v2 ([#349](https://github.com/laravel/scout/pull/349), [#353](https://github.com/laravel/scout/pull/353)) ## [v6.1.3 (2018-12-11)](https://github.com/laravel/scout/compare/v6.1.2...v6.1.3) ### Fixed -- Pass plain array to newCollection method ([68fbcd1](https://github.com/laravel/scout/commit/68fbcd1e67fd1e0b9ee8ba32ece2e68e28630c7e)) +- Pass plain array to newCollection method ([68fbcd1](https://github.com/laravel/scout/commit/68fbcd1e67fd1e0b9ee8ba32ece2e68e28630c7e)) ## [v6.1.2 (2018-12-11)](https://github.com/laravel/scout/compare/v6.1.1...v6.1.2) ### Fixed -- Use Model collection where appropriate ([#334](https://github.com/laravel/scout/pull/334)) +- Use Model collection where appropriate ([#334](https://github.com/laravel/scout/pull/334)) ## [v6.1.1 (2018-11-20)](https://github.com/laravel/scout/compare/v6.1.0...v6.1.1) ### Added -- Builder implementation can be changed using the container ([#322](https://github.com/laravel/scout/pull/322)) +- Builder implementation can be changed using the container ([#322](https://github.com/laravel/scout/pull/322)) ## [v6.1.0 (2018-11-19)](https://github.com/laravel/scout/compare/v6.0.0...v6.1.0) ### Fixed -- Fix soft delete on `Searchable` trait ([#321](https://github.com/laravel/scout/pull/321)) +- Fix soft delete on `Searchable` trait ([#321](https://github.com/laravel/scout/pull/321)) ### Changed -- Skip empty updates for `AlgoliaEngine` ([#318](https://github.com/laravel/scout/pull/318)) +- Skip empty updates for `AlgoliaEngine` ([#318](https://github.com/laravel/scout/pull/318)) ## [v6.0.0 (2018-10-08)](https://github.com/laravel/scout/compare/v5.0.3...v6.0.0) ### Changed -- Adds default `$query` value on `Searchable::search` ([#309](https://github.com/laravel/scout/pull/309)) -- Flush records of a model using the engine. **This removes the emitting of the `ModelsFlushed` event.** ([#310](https://github.com/laravel/scout/pull/310)) +- Adds default `$query` value on `Searchable::search` ([#309](https://github.com/laravel/scout/pull/309)) +- Flush records of a model using the engine. **This removes the emitting of the `ModelsFlushed` event.** ([#310](https://github.com/laravel/scout/pull/310)) From 1dc06d0c89c4c3c92e3776b84131147b1e5f4134 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Wed, 7 Dec 2022 18:30:22 -0500 Subject: [PATCH 20/21] Remove `getUnqualifiedScoutKeyName()` --- src/Searchable.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Searchable.php b/src/Searchable.php index a7f9f467..c153785a 100644 --- a/src/Searchable.php +++ b/src/Searchable.php @@ -392,16 +392,6 @@ public function getScoutKeyName() return $this->getKeyName(); } - /** - * Get the unqualified Scout key name. - * - * @return string - */ - public function getUnqualifiedScoutKeyName() - { - return Str::afterLast($this->getScoutKeyName(), '.'); - } - /** * Determine if the current class should use soft deletes with searching. * From 1806b0c8272211c54b9857054fc54c18737208f6 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Wed, 7 Dec 2022 18:31:40 -0500 Subject: [PATCH 21/21] Remove unused import --- src/Searchable.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Searchable.php b/src/Searchable.php index c153785a..d873aacc 100644 --- a/src/Searchable.php +++ b/src/Searchable.php @@ -4,7 +4,6 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Collection as BaseCollection; -use Illuminate\Support\Str; trait Searchable {