-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Builder ignores Model custom Collection when getting data #188
Labels
Comments
Hmm, I can see this being useful. @nunomaduro @taylorotwell do you guys want to weigh in here? I could send in a PR for this. Just replacing |
@ziabice Thanks for bringing that up to our attention. @driesvints I also agree with the proposed solution. 👍 |
sonnysantino
pushed a commit
to sonnysantino/scout
that referenced
this issue
Jan 17, 2020
* fix branch alias * remove elastic driver so it can be extracted to package * fix a few bugs * remove elastic config * Update scout.php * Remove references to elasticsearch in composer.json Since elasticsearch is no longer supported as part of the main package removing elasticsearch from keywords and elasticsearch/elasticsearch from the suggests. * add config options to scout.php to allow specifying connection and queue * tweak config options * update branch alias * update dependencies * remove event listener * Allow for customizing searchable chunk size * use 500 as chunk size * Add Laravel Scout user agent to Algolia queries * update formatting * update formatting * update readme * Update readme.md * Update readme.md * Update readme.md * Update readme.md * Update readme.md * Update readme.md * Update ScoutServiceProvider.php * Update ScoutServiceProvider.php * Return the result from callback in withoutSyncingToSearch * Added SCOUT_QUEUED to .env * Update scout.php * Update scout.php * Add macro able * Add getSearchResults * Update Builder.php * support auto-discovery coming in Laravel 5.5 * Chain `values` method in map function refer to my pull request in ErickTamayo/laravel-scout-elastic#66 * Some composer adjustments. * Configure/optimize bulk chunk sizes * formatting * allow passing chunk size * fix for php5.6, ternary operation should be sufficient since the $chunk is defined * Fix Chunk typo How much wood could a wood chuck chunk? * don't use deprecated $custom_value * Add paginateRaw method to Builder class * Revert "Add paginateRaw method to Builder class" This reverts commit e47dfa6. * Rewrite paginateRaw method for Builder class * Use string "null" if default driver is set to NULL * Fix PHP 5.6 compatibility for null driver See laravel#224 * Update `AlgoliaUserAgent` version * Write model chunk id segments to the console when calling flush command. * Updated to PHPUnit 6 and Mockery 1 * ability to keep soft deleted records * formatting * Test against PHP 7.2 * add only trashed method * soft deletion improvements * remove unnecessary code * improve import command * Conditionally make a model instance searchable * formatting * Import only searchable models when performing a bulk import using the EloquentBuilder * Listen to saved event instead of created and updated * Remove unused variables in closures * Fix typo * Remove non existent params * Keep Scout Builder uncoupled from the config and the framework helpers * Fix variable casing * formatting * handle force deleted event * Implement syncing for conditional models * Simplified the delete process * Cleanup the test * Style fix * Make syncing the default behaviour * Remove sync config key * Fix test case * using a custom key for search engine instead of the eloquent key fixes laravel#44 fixes laravel#267 * formatting * Adding the Eloquent SoftDeletes class to index soft delete objects when i run php artisan scout import command * Update git `dev-master` branch alias Fix laravel#278 * Add getScoutKeyName() and mapScoutSearchResults() functions. * We cannot assume that getScoutKey() will be a model attribute. We need to check one by one. * refactor * wip * update branch alias * allow query callback * change branch alias * fix for missing queryCallback property in Builder class * formatting * Update NullEngine.php Fixing the map function from amends a few days ago, * add "when" & "tap" on builder * formatting * Fix undefined variable: queryCallback * use HTTPS links where appropriate both of these links redirect to HTTPS sites, so let's just send them directly there. * add missing period * Adds changelog * Adds default $query value on Searchable::search * wip * Use engine to flush records of model Instead of iterating over ids from the database we use the engine itself to flush the records of an index/model. This solves the problem where models would get out of sync with the search records and old records weren't flushed. With this implementation all records are always removed. If there are engines which don't provide this functionality they can still iterate over the model ids if they want to. See laravel#101 * Add changelog * Add 5.0 changes * Code review feedback * Fix changelog link * Remove unused import * Add note about removal of event * update cl * Skip empty updates * Add skip empty updates test * Update AlgoliaEngine.php * Update .travis.yml * Don't add soft delete where on hard delete models * Add soft delete check functionality to trait * Cleanup * Update changelog * Allows to change the builder implementation using the container * No need to inject the dispatcher. * Remove useless imports, and ensure they are properly sorted. * New without braces. * Disable xdebug * Fixes CHANGELOG for v6.1.1 * Removes elasticsearch service from .travis.yml * Unify test namespaces * Use Model collection where appropriate This way when the model's collection is overwritten it still gets applied. Fixes laravel#188 * Pass plain array to newCollection method * Update changelog * Update changelog * Update changelog * Update branch-alias * Update .editorconfig * Fix a docblock. * Upgrades Algolia API client to V2. * Adds custom user agent when using Algolia * Adds UPGRADE.md * Adds better feedback when algoliasearch-client-php is not correctly installed * Updates CHANGELOG.md * formatting * update change log * Fixes typo on Algolia dependency warning * Remove test stub ModelStubForRemoveAllFromSearch * Update versioning of Illuminate components * Add support for Laravel 5.8 * Update changelog * Update license file * Remove support for PHP 7.0 * Matrix build * Github templates * Update changelog * Fix return type * Import classes * Refactor test suite For some reason there were way more fixtures then there were suppose to be. This commit refactors the fixtures so they're included in the only classes they're used and reduces them to only the minimum amount needed. * Correctly sort Algolia results This commit fixes the sorting of Algolia results. Instead of letting this get reset by the collection we should use the sorting results from Algolia itself since it already correctly sorts the search results. * Refactor config call to constructor arg This refactor allows us to pass in the value of the soft delete setting with the constructor of the engine instead of a function call in the class itself. This allows us to more easily test the behavior of the engine. * Ignore metadata when skipping records When skipping records during updates on Algolia items, we should ignore any metadata as this shouldn't be a factor on wether to index or not. Only records which have at least one key value pair for indexing should be indexed. This fixes a bug where empty records with soft deleted enabled were still being updated: laravel#350 * Fix test * Flip object ids for ID lookup By flipping the object ids as keys their positions become the values of the array and it becomes easier to look them up. This way we don't need to do a separate time-consuming array_search call for each item. * Update changelog * Update changelog * Calling values() on sorted collection to reset the array keys and prevent unexpected sorting when returning as json. * Simulating the use of the sorted model collection to ensure the array keys were reset during sorting. Not resetting the keys in the Engine map method now produces a failed test. * Simplifying test to ensure array keys have been reset after sorting. * Add styleci config * Apply fixes from StyleCI (laravel#373) * Format * Add .styleci.yml to .gitattributes * Update changelog * Fixing PHPdoc referencing session driver I think this is a copy/paste from https://github.com/laravel/framework/blob/e6c8aa0e39d8f91068ad1c299546536e9f25ef63/src/Illuminate/Session/SessionManager.php#L204 and is not meant to say `session` but rather `Scout`. * Update composer.json * Update CHANGELOG.md * Rename readme.md to README.md * Prepare for Laravel 6.0 release * Update PHPUnit methods * Order imports alphabetically * Apply fixes from StyleCI (laravel#381) * Add __call() method to AlgoliaEngine This allows calling the Algolia search client's methods like `multipleQueries()` easily. * formatting * Removed legacy phpunit flag That configuration setting has not had an effect in years. It was removed long ago. * Update .gitignore file * Tests against Laravel 5.6 * Update CHANGELOG.md * version * Update CHANGELOG.md * Fix config scout elastic Co-authored-by: Taylor Otwell <taylor@laravel.com> Co-authored-by: Alexandr Chernyaev <bliz48rus@gmail.com> Co-authored-by: Mark Davidson <mark@4each.co.uk> Co-authored-by: Michael St Clair <michaelst57@gmail.com> Co-authored-by: Kuba Szymanowski <kuba.szymanowski@inf24.pl> Co-authored-by: Raymond Rutjes <raymond.rutjes@gmail.com> Co-authored-by: Aaron Collegeman <aaron@collegeman.net> Co-authored-by: Joaquín Marcher <joaquin@marcher.com.uy> Co-authored-by: Florian Wartner <fwartner@users.noreply.github.com> Co-authored-by: Michael Lundbøl <michael.lundboel@gmail.com> Co-authored-by: Joren Van Hee <jorenvanhee@gmail.com> Co-authored-by: Andrew Brown <browner12@gmail.com> Co-authored-by: Joey <joey.xf@gmail.com> Co-authored-by: Lucas Michot <lucas@semalead.com> Co-authored-by: Charles Peterson <artistan@gmail.com> Co-authored-by: Aaron Ranard <aaronranard@gmail.com> Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com> Co-authored-by: Karam Qubsi <karamqubsi@gmail.com> Co-authored-by: Chris Morrell <inxilpro@users.noreply.github.com> Co-authored-by: Julien Bourdeau <julien@sigerr.ch> Co-authored-by: Aaron Costello <aaronjamescos@gmail.com> Co-authored-by: Gabriel Caruso <carusogabriel34@gmail.com> Co-authored-by: Mohamed Said <themsaid@gmail.com> Co-authored-by: Kfir Ben-Ami <kfirba2@gmail.com> Co-authored-by: Alexander Diachenko <adiach3nko@gmail.com> Co-authored-by: Peter Matseykanets <pmatseykanets@users.noreply.github.com> Co-authored-by: Arjan Westdorp <arjanwestdorp@gmail.com> Co-authored-by: OliverHolz <37249319+OliverHolz@users.noreply.github.com> Co-authored-by: julien-consumerlab <jbunel@colorado-consumerlab.com> Co-authored-by: tsjason <jason@tough.space> Co-authored-by: Adam Gowland <Hoglan@users.noreply.github.com> Co-authored-by: binotaliu <59665613+binotaliu@users.noreply.github.com> Co-authored-by: Gabriel Rausch <gdsrmygdsrjr@gmail.com> Co-authored-by: Nuno Maduro <enunomaduro@gmail.com> Co-authored-by: Dries Vints <dries.vints@gmail.com> Co-authored-by: mnightingale <mike@mike-nightingale.co.uk> Co-authored-by: Andrey Bolonin <andreybolonin@users.noreply.github.com> Co-authored-by: Mark van den Broek <mvdnbrk@gmail.com> Co-authored-by: Trevor Fitzgerald <fitztrev@users.noreply.github.com> Co-authored-by: Jason Hill <jason@redshiftwebdesign.com> Co-authored-by: Chris Thompson <christhompsontldr@gmail.com> Co-authored-by: João Roberto P. Borges <joaorobertopb@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In my project I use a Model that returns a custom Collection subclass (I redefined the
Model::newCollection()
method).The problem is that Scout Builder class completely ignores this new collection and instead returns a standard Eloquent\Collection: this breaks my code and seems to me the wrong behavior.
This issue affects
Builder::paginate()
andEngine::get()
.The solution to this problem is very trivial: let
Engine::map()
return the right Collection type (it should already, because of it's signature that tells that the return type will be a\Illuminate\Database\Eloquent\Collection
or a subclass), then pass as-is the collection.This means that at a certain point into your
Engine::map()
method you'll do:Attached there's a patch that should fix this annoying issue.
commit-f30d7bf.txt
The text was updated successfully, but these errors were encountered: