Skip to content
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

Support experimental features endpoints #594

Open
wants to merge 3 commits into
base: main
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
4 changes: 4 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,10 @@ multi_search_1: |-
{ index_uid: 'movies', q: 'nemo', limit: 5 }
{ index_uid: 'movie_ratings', q: 'us' }
])
get_experimental_features_1: |-
client.experimental_features
update_experimental_features_1: |-
client.update_experimental_features(metrics: true)
facet_search_1: |-
client.index('books').facet_search('genres', 'fiction', filter: 'rating > 3')
facet_search_2: |-
Expand Down
11 changes: 11 additions & 0 deletions lib/meilisearch/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ def batch(batch_uid)
http_get "/batches/#{batch_uid}"
end

### EXPERIMENTAL FEATURES

def experimental_features
http_get '/experimental-features'
end

def update_experimental_features(expe_feat_changes)
expe_feat_changes = Utils.transform_attributes(expe_feat_changes)
http_patch '/experimental-features', expe_feat_changes
end

private

def index_object(uid, primary_key = nil)
Expand Down
60 changes: 60 additions & 0 deletions spec/meilisearch/client/experimental_features_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: true

RSpec.describe 'Meilisearch::Client - Experimental features' do
let(:index) { client.index(random_uid) }

describe '#experimental_features' do
it 'returns the available experimental features' do
expect(client.experimental_features).to include(
'metrics',
'editDocumentsByFunction',
'logsRoute',
'vectorStore',
'containsFilter'
)
end
end

context '#update_experimental_features' do
context 'when given one key' do
it 'updates that one key' do
client.update_experimental_features(metrics: true)
expect(client.experimental_features).to include('metrics' => true)

client.update_experimental_features(metrics: false)
expect(client.experimental_features).to include('metrics' => false)
end

it 'does not change others' do
prev_features = client.experimental_features

client.update_experimental_features(metrics: true)
expect(client.experimental_features).to include(**prev_features.except('metrics'))
end
end

context 'when given all of the keys' do
it 'sets all keys' do
features = client.experimental_features
features[:metrics] = features.delete('metrics')
features[:logs_route] = features.delete('logsRoute')
features[:contains_filter] = !features.delete('containsFilter')
features[:edit_documents_by_function] = !features.delete('editDocumentsByFunction')
features[:vector_store] = !features.delete('vectorStore')

client.update_experimental_features(features)
expect(client.experimental_features).to eq(
Meilisearch::Utils.transform_attributes(features)
)
end
end

context 'when given an invalid feature' do
it 'raises an error' do
expect do
client.update_experimental_features(penguins: true)
end.to raise_error(Meilisearch::ApiError)
end
end
end
end
Loading