craft-scout icon indicating copy to clipboard operation
craft-scout copied to clipboard

Proxy __call for access to search client methods

Open timkelty opened this issue 6 years ago • 6 comments

I needed access to the client for one-off algolia operations, but rias\scout\engines\AlgoliaEngine::algolia was protected, so I couldn't.

This adds a getter, and should be non-breaking.

For a breaking change, it might make sense to move getClient to the base class, make the prop private, maybe rename to $client?

Conceptually at least, is the idea here that there might be a non-algolia engine (eg elasticsearch)?

timkelty avatar Nov 29 '19 23:11 timkelty

Just noticed that laravel\scout uses a __call so you can just call any methods on the algolia client directly: https://github.com/laravel/scout/blob/7.0/src/Engines/AlgoliaEngine.php#L232-L242

timkelty avatar Nov 30 '19 00:11 timkelty

Oooh I like the __call to proxy to the Algolia client, you can implement that instead if you want

riasvdv avatar Dec 02 '19 08:12 riasvdv

…It also might make sense to have a getIndex method, since we do this in several places:

        $index = $this->algolia->initIndex($this->scoutIndex->indexName);

timkelty avatar Dec 02 '19 14:12 timkelty

Codecov Report

Merging #122 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##             master   #122   +/-   ##
=======================================
  Coverage       100%   100%           
- Complexity      127    128    +1     
=======================================
  Files            17     17           
  Lines           429    431    +2     
=======================================
+ Hits            429    431    +2
Impacted Files Coverage Δ Complexity Δ
src/engines/AlgoliaEngine.php 100% <100%> (ø) 16 <1> (+1) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update e61adeb...7c8d187. Read the comment docs.

codecov[bot] avatar Dec 02 '19 14:12 codecov[bot]

Ok, @riasvdv I changed it to use the __call proxy instead.

timkelty avatar Dec 02 '19 14:12 timkelty

Hmmm…so upon further reflection, this might need some more thought…

While I can get the client now, it is not yet configured, which kind of defeats the purpose of getting it through the scout engine…

I'll open an issue for discussion on the best approach.

timkelty avatar Dec 02 '19 15:12 timkelty