Skip to content

Commit

Permalink
Remove search callback call (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaconnier authored Jul 14, 2023
1 parent 6e103a2 commit eeab28d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 35 deletions.
10 changes: 0 additions & 10 deletions src/Engines/ArrayEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,6 @@ protected function performSearch(Builder $builder, array $options = [])
{
$index = $builder->index ?: $builder->model->searchableAs();

if ($builder->callback) {
return call_user_func(
$builder->callback,
$this->store,
$index,
$builder->query,
$options
);
}

$matches = $this->store->find($index, function ($record) use ($builder) {
$values = new RecursiveIteratorIterator(new RecursiveArrayIterator($record));

Expand Down
26 changes: 1 addition & 25 deletions tests/Engines/ArrayEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,31 +90,7 @@ public function search_results_can_be_limited()
$this->assertCount(2, $results['hits']);
$this->assertEquals(3, $results['total']);
}

/** @test */
public function callback_can_be_passed_to_search()
{
$arrayStore = new ArrayStore();
$engine = new ArrayEngine($arrayStore);
$engine->update(Collection::make([
new SearchableModel(['id' => 1, 'foo' => 'bar', 'scoutKey' => 1]),
new SearchableModel(['id' => 2, 'foo' => 'baz', 'scoutKey' => 2]),
new SearchableModel(['id' => 3, 'foo' => 'bar', 'scoutKey' => 3])
]));

$wasCalled = false;
$builder = new Builder(new SearchableModel, 'bar', function ($store, $index, $query) use (&$wasCalled, $arrayStore) {
$wasCalled = true;
$this->assertSame($store, $arrayStore);
$this->assertEquals($index, (new SearchableModel())->searchableAs());
$this->assertEquals('bar', $query);
});

$engine->search($builder);

$this->assertTrue($wasCalled);
}


/** @test */
public function it_returns_empty_array_if_no_results_found()
{
Expand Down

0 comments on commit eeab28d

Please sign in to comment.