Skip to content
This repository has been archived by the owner on Feb 5, 2023. It is now read-only.

chain values method in map function #66

Merged
merged 1 commit into from
Jul 2, 2017

Conversation

xcaptain
Copy link
Contributor

@xcaptain xcaptain commented Jul 2, 2017

collect($results['hits']['hits'])->map(function ($hit) use ($model, $models) {
    return isset($models[$hit['_id']]) ? $models[$hit['_id']] : null;
})->filter();

when using paginate() the returened data property would contains some null values which makes data to be an object rather than list.

In 
```php
    collect($results['hits']['hits'])->map(function ($hit) use ($model, $models) {
            return isset($models[$hit['_id']]) ? $models[$hit['_id']] : null;
        })->filter();
```
would generate some holds which would cause `paginate` results objects rather than list.
xcaptain added a commit to xcaptain/scout that referenced this pull request Jul 2, 2017
@ErickTamayo ErickTamayo merged commit 4128cbe into ErickTamayo:master Jul 2, 2017
@xcaptain xcaptain deleted the patch-2 branch July 2, 2017 16:45
sonnysantino pushed a commit to sonnysantino/laravel-scout-elastic that referenced this pull request Jan 17, 2020
* Updating 0.0.1 (ErickTamayo#8)

* fixing config key + updating the Usage on README (ErickTamayo#6)

* Rename ElasticsearchEngineTets.php to ElasticsearchEngineTest.php (ErickTamayo#7)

* Updating 0.0.1 (ErickTamayo#11)

* fixing config key + updating the Usage on README (ErickTamayo#6)

* Rename ElasticsearchEngineTets.php to ElasticsearchEngineTest.php (ErickTamayo#7)

* Update ElasticsearchEngine.php (ErickTamayo#10)

* Updating 0.0.1 (ErickTamayo#14)

* fixing config key + updating the Usage on README (ErickTamayo#6)

* Rename ElasticsearchEngineTets.php to ElasticsearchEngineTest.php (ErickTamayo#7)

* Update ElasticsearchEngine.php (ErickTamayo#10)

* optimized creation of params array for better performance when dealing with huge amount of models (ErickTamayo#13)

* Make stable (ErickTamayo#18) (ErickTamayo#19)

* Bumped Scout version to v2.0.x
Bumped elasticsearch/elasticsearch to v5.0

* Bumped Scout version to 3.0

* Fix config name (ErickTamayo#35)

* v3.0.2

bumping to php 5.6.6 (Earliest version that can support php elasticsearch) (ErickTamayo#48)
`within` now is being taken into account when specified ErickTamayo#31
Now if the record is not found on the db will not throw undefined offset ErickTamayo#36
Implemented orderBy ErickTamayo#46

* Update ElasticsearchProvider.php (ErickTamayo#54)

use `app` instead of `resolve` to make lumen 5.4 compatible.

`app` and `resolve` are identical since 5.4, see https://github.com/laravel/framework/blob/5.4/src/Illuminate/Foundation/helpers.php#L690

* chain `values` method in `map` function (ErickTamayo#66)

In 
```php
    collect($results['hits']['hits'])->map(function ($hit) use ($model, $models) {
            return isset($models[$hit['_id']]) ? $models[$hit['_id']] : null;
        })->filter();
```
would generate some holds which would cause `paginate` results objects rather than list.

* Support for "WHERE IN" searches if array is passed to `where` (ErickTamayo#55)

Right now passing an array results in: "illegal_state_exception: Can't get text on a START_ARRAY"
Solution based on http://stackoverflow.com/a/40737488/7362396

* Execute the callback that can be passed to the Builder in performSearch (ErickTamayo#56)

Context: laravel/scout#111

Implementation analogical to the official AlgoliaEngine implementation: https://github.com/laravel/scout/blob/v3.0.3/src/Engines/AlgoliaEngine.php#L112-L119

* Update ElasticsearchEngine.php (ErickTamayo#51)

Predefine elastic variable.

* Enable Laravel5.5 package Auto-Discovery (ErickTamayo#81)

* Removed count function. Fixes ErickTamayo#80 (ErickTamayo#84)

Since php 7.2, count a number will generate a warning. Because
$results['hits']['total'] is a number we can just compare it to zero.

`if ($results['hits']['total'] === 0)`

* Allow installation with Scout 4 (ErickTamayo#99)

* Compatibility with Scout 5 (ErickTamayo#106)

* Compatibility with Scout 5

No "cross-installation" possible due to changed method signature

Pass around new $builder var

Also: Use getScoutModelsByIds/getScoutKey

Inspired by laravel/scout@4.0...5.0#diff-f2faa85f27580a9b67d73a8a273bfef1 / laravel/scout@9f06b9c

* Remove PHP5 as laravel/scout^5 / laravel5.6 also removed it

* Added support for Laravel Scout 6.0 and 7.0, Laravel 5.8 (ErickTamayo#119)

* Elasticsearch downgrade

Co-authored-by: Erick Tamayo <ErickTamayo@users.noreply.github.com>
Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com>
Co-authored-by: Joey <joey.xf@gmail.com>
Co-authored-by: Tobias Kronthaler <kronthto@users.noreply.github.com>
Co-authored-by: Nirav <nirav.t.prajapati21@gmail.com>
Co-authored-by: Camilo <camilo.castro.cabrera@gmail.com>
Co-authored-by: Semyon Chetvertnyh <semyon.chetvertnyh@gmail.com>
sonnysantino pushed a commit to sonnysantino/scout that referenced this pull request 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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants