Skip to content

feat: add support for Meilisearch embedder settings #928

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

Open
wants to merge 3 commits into
base: 10.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Engines/MeilisearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Scout\Engines;

use Illuminate\Support\Arr;
use Illuminate\Support\LazyCollection;
use Laravel\Scout\Builder;
use Laravel\Scout\Contracts\UpdatesIndexSettings;
Expand Down Expand Up @@ -395,7 +396,13 @@ public function createIndex($name, array $options = [])
*/
public function updateIndexSettings($name, array $settings = [])
{
$this->meilisearch->index($name)->updateSettings($settings);
$index = $this->meilisearch->index($name);

$index->updateSettings(Arr::except($settings, 'embedders'));

if (! empty($settings['embedders'])) {
$index->updateEmbedders($settings['embedders']);
}
}

/**
Expand Down
28 changes: 28 additions & 0 deletions tests/Unit/MeilisearchEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Laravel\Scout\Engines\MeilisearchEngine;
use Laravel\Scout\Tests\Fixtures\SearchableModel;
use Meilisearch\Client;
use Meilisearch\Endpoints\Indexes;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use stdClass;
Expand Down Expand Up @@ -242,6 +243,33 @@ public function test_engine_returns_hits_entry_from_search_response()
'totalHits' => 3,
]) === 3);
}

public function test_update_index_settings_with_embedders()
{
$client = m::mock(Client::class);
$index = m::mock(Indexes::class);

$client->shouldReceive('index')
->with('test_index')
->once()
->andReturn($index);

$index->shouldReceive('updateSettings')
->with(['searchableAttributes' => ['title']])
->once();

$index->shouldReceive('updateEmbedders')
->with(['default' => ['source' => 'openAi']])
->once();

$engine = new MeilisearchEngine($client);
$engine->updateIndexSettings('test_index', [
'searchableAttributes' => ['title'],
'embedders' => ['default' => ['source' => 'openAi']],
]);

$this->assertTrue(true);
}
}

class MeilisearchCustomKeySearchableModel extends SearchableModel
Expand Down