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

Changed camel case keywords to snake case #278

Merged
merged 4 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
42 changes: 21 additions & 21 deletions lib/meilisearch-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ class IndexSettings

# Meilisearch settings
OPTIONS = %i[
searchableAttributes
filterableAttributes
sortableAttributes
displayedAttributes
distinctAttribute
searchable_attributes
filterable_attributes
sortable_attributes
displayed_attributes
distinct_attribute
synonyms
stopWords
rankingRules
attributesToHighlight
attributesToCrop
cropLength
stop_words
ranking_rules
attributes_to_highlight
attributes_to_crop
crop_length
pagination
faceting
typoTolerance
typo_tolerance
].freeze

CAMELIZE_OPTIONS = %i[pagination faceting typoTolerance].freeze
CAMELIZE_OPTIONS = %i[pagination faceting typo_tolerance].freeze

OPTIONS.each do |option|
define_method option do |value|
Expand Down Expand Up @@ -265,9 +265,9 @@ def initialize(index_uid, raise_on_failure, options)
::MeiliSearch::Index.instance_methods(false).each do |m|
define_method(m) do |*args, &block|
if m == :update_settings
args[0].delete(:attributesToHighlight) if args[0][:attributesToHighlight]
args[0].delete(:attributesToCrop) if args[0][:attributesToCrop]
args[0].delete(:cropLength) if args[0][:cropLength]
args[0].delete(:attributes_to_highlight) if args[0][:attributes_to_highlight]
args[0].delete(:attributes_to_crop) if args[0][:attributes_to_crop]
args[0].delete(:crop_length) if args[0][:crop_length]
end

SafeIndex.log_or_throw(m, @raise_on_failure) do
Expand Down Expand Up @@ -581,15 +581,15 @@ def ms_clear_index!(synchronous = false)
def ms_raw_search(q, params = {})
index_uid = params.delete(:index) || params.delete('index')

unless meilisearch_settings.get_setting(:attributesToHighlight).nil?
params[:attributesToHighlight] = meilisearch_settings.get_setting(:attributesToHighlight)
unless meilisearch_settings.get_setting(:attributes_to_highlight).nil?
params[:attributes_to_highlight] = meilisearch_settings.get_setting(:attributes_to_highlight)
end

unless meilisearch_settings.get_setting(:attributesToCrop).nil?
params[:attributesToCrop] = meilisearch_settings.get_setting(:attributesToCrop)
unless meilisearch_settings.get_setting(:attributes_to_crop).nil?
params[:attributes_to_crop] = meilisearch_settings.get_setting(:attributes_to_crop)

unless meilisearch_settings.get_setting(:cropLength).nil?
params[:cropLength] = meilisearch_settings.get_setting(:cropLength)
unless meilisearch_settings.get_setting(:crop_length).nil?
params[:crop_length] = meilisearch_settings.get_setting(:crop_length)
end
end

Expand Down
19 changes: 10 additions & 9 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,20 @@
describe 'Settings change detection' do
it 'detects settings changes' do
expect(Color.send(:meilisearch_settings_changed?, nil, {})).to be(true)
expect(Color.send(:meilisearch_settings_changed?, {}, { 'searchableAttributes' => ['name'] })).to be(true)
expect(Color.send(:meilisearch_settings_changed?, { 'searchableAttributes' => ['name'] },
{ 'searchableAttributes' => %w[name hex] })).to be(true)
expect(Color.send(:meilisearch_settings_changed?, { 'searchableAttributes' => ['name'] },
{ 'rankingRules' => ['words', 'typo', 'proximity', 'attribute', 'sort', 'exactness', 'hex:asc'] })).to be(true)
expect(Color.send(:meilisearch_settings_changed?, {}, { 'searchable_attributes' => ['name'] })).to be(true)
expect(Color.send(:meilisearch_settings_changed?, { 'searchable_attributes' => ['name'] },
{ 'searchable_attributes' => %w[name hex] })).to be(true)
expect(Color.send(:meilisearch_settings_changed?, { 'searchable_attributes' => ['name'] },
{ 'ranking_rules' => ['words', 'typo', 'proximity', 'attribute', 'sort', 'exactness', 'hex:asc'] })).to be(true)
end

it 'does not detect settings changes' do
expect(Color.send(:meilisearch_settings_changed?, {}, {})).to be(false)
expect(Color.send(:meilisearch_settings_changed?, { 'searchableAttributes' => ['name'] },
{ searchableAttributes: ['name'] })).to be(false)
expect(Color.send(:meilisearch_settings_changed?, { 'searchable_attributes' => ['name'] },
{ searchable_attributes: ['name'] })).to be(false)
expect(Color.send(:meilisearch_settings_changed?,
{ 'searchableAttributes' => ['name'], 'rankingRules' => ['words', 'typo', 'proximity', 'attribute', 'sort', 'exactness', 'hex:asc'] }, { 'rankingRules' => ['words', 'typo', 'proximity', 'attribute', 'sort', 'exactness', 'hex:asc'] })).to be(false)
{ 'searchable_attributes' => ['name'], 'ranking_rules' => ['words', 'typo', 'proximity', 'attribute', 'sort', 'exactness', 'hex:asc'] },
{ 'ranking_rules' => ['words', 'typo', 'proximity', 'attribute', 'sort', 'exactness', 'hex:asc'] })).to be(false)
end
end

Expand Down Expand Up @@ -536,7 +537,7 @@
it 'sanitizes attributes' do
_hack = Book.create! name: '"><img src=x onerror=alert(1)> hack0r',
author: '<script type="text/javascript">alert(1)</script>', premium: true, released: true
b = Book.raw_search('hack', { attributesToHighlight: ['*'] })
b = Book.raw_search('hack', { attributes_to_highlight: ['*'] })
expect(b['hits'].length).to eq(1)
begin
expect(b['hits'][0]['name']).to eq('"> hack0r').and_raise(StandardError)
Expand Down
Loading