Skip to content

Commit

Permalink
support extra algolia parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Aug 5, 2015
1 parent d82b806 commit 142f07e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to laravel-glide will be documented in this file.

### 3.1.1
- Fixed a bug that caused using extra Algolia query parameters to throw an exception.

### 3.1.0
- Added `removeFromIndexByTypeAndId` method

Expand Down
27 changes: 26 additions & 1 deletion spec/SearchIndexHandlers/AlgoliaSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,32 @@ public function it_can_get_search_results(\AlgoliaSearch\Index $index)
{
$query = 'this is a testquery';

$index->search($query)->shouldBeCalled();
$index->search($query, [])->shouldBeCalled();

$this->getResults($query);
}

public function it_can_get_search_results_using_an_array(\AlgoliaSearch\Index $index)
{
$query = [
'query' => 'raw query',
'param1' => 'yes',
'param2' => 'no',
];

$index->search('raw query', ['param1' => 'yes', 'param2' => 'no'])->shouldBeCalled();

$this->getResults($query);
}

public function it_can_get_search_results_using_an_array_without_a_query_key(\AlgoliaSearch\Index $index)
{
$query = [
'param1' => 'yes',
'param2' => 'no',
];

$index->search('', ['param1' => 'yes', 'param2' => 'no'])->shouldBeCalled();

$this->getResults($query);
}
Expand Down
13 changes: 12 additions & 1 deletion src/SearchIndexHandlers/Algolia.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\SearchIndex\SearchIndexHandlers;

use AlgoliaSearch\Client;
use Illuminate\Support\Collection;
use Spatie\SearchIndex\Searchable;
use Spatie\SearchIndex\SearchIndexHandler;

Expand Down Expand Up @@ -92,7 +93,17 @@ public function clearIndex()
*/
public function getResults($query)
{
return $this->index->search($query);
$parameters = [];

if (is_array($query)) {
$collection = new Collection($query);

$query = $collection->pull('query', '');

$parameters = $collection->toArray();
}

return $this->index->search($query, $parameters);
}

/**
Expand Down

0 comments on commit 142f07e

Please sign in to comment.