diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml
index c2de6da2..c87dc472 100644
--- a/.code-samples.meilisearch.yaml
+++ b/.code-samples.meilisearch.yaml
@@ -224,12 +224,23 @@ search_parameter_guide_retrieve_1: |-
search_parameter_guide_crop_1: |-
client.index('movies').search('shifu', {
attributes_to_crop: ['overview'],
- cropLength: 10
+ crop_length: 5
+ })
+search_parameter_guide_crop_marker_1: |-
+ client.index('movies').search('shifu', {
+ attributes_to_crop: ['overview'],
+ crop_marker: "[…]"
})
search_parameter_guide_highlight_1: |-
client.index('movies').search('winter feast', {
attributes_to_highlight: ['overview']
})
+search_parameter_guide_highlight_tag_1: |-
+ client.index('movies').search('winter feast', {
+ attributes_to_highlight: ['overview'],
+ highlight_pre_tag: '',
+ highlight_post_tag: ''
+ })
search_parameter_guide_matches_1: |-
client.index('movies').search('winter feast', {
matches: true
diff --git a/.github/workflows/pre-release-tests.yml b/.github/workflows/pre-release-tests.yml
index 3c8fcba3..b9b34baf 100644
--- a/.github/workflows/pre-release-tests.yml
+++ b/.github/workflows/pre-release-tests.yml
@@ -27,6 +27,6 @@ jobs:
- name: Get the latest MeiliSearch RC
run: echo "MEILISEARCH_VERSION=$(curl https://raw.githubusercontent.com/meilisearch/integration-guides/main/scripts/get-latest-meilisearch-rc.sh | bash)" >> $GITHUB_ENV
- name: MeiliSearch (${{ env.MEILISEARCH_VERSION }}) setup with Docker
- run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} ./meilisearch --master-key=masterKey --no-analytics
+ run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} meilisearch --master-key=masterKey --no-analytics
- name: Run test suite
run: bundle exec rspec
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 62cc8d95..2dcff574 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -29,7 +29,7 @@ jobs:
- name: Install ruby dependencies
run: bundle install --with test
- name: MeiliSearch (latest) setup with Docker
- run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey --no-analytics
+ run: docker run -d -p 7700:7700 getmeili/meilisearch:latest meilisearch --master-key=masterKey --no-analytics
- name: Run test suite
run: bundle exec rspec
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index c52bc2f1..a6e2df64 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -1,13 +1,13 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
-# on 2021-12-13 22:26:31 UTC using RuboCop version 1.23.0.
+# on 2022-04-26 02:54:29 UTC using RuboCop version 1.26.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 1
-# Cop supports --auto-correct.
+# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: Include.
# Include: **/*.gemspec
Gemspec/RequireMFA:
@@ -15,21 +15,21 @@ Gemspec/RequireMFA:
- 'meilisearch.gemspec'
# Offense count: 1
-# Cop supports --auto-correct.
+# This cop supports safe auto-correction (--auto-correct).
Layout/HeredocIndentation:
Exclude:
- 'spec/meilisearch/index/documents_spec.rb'
-# Offense count: 33
+# Offense count: 43
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
# IgnoredMethods: refine
Metrics/BlockLength:
- Max: 557
+ Max: 558
-# Offense count: 1
+# Offense count: 2
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
- Max: 278
+ Max: 277
# Offense count: 1
# Configuration parameters: Max, CountKeywordArgs.
diff --git a/README.md b/README.md
index d1723bb1..3a6cfd6f 100644
--- a/README.md
+++ b/README.md
@@ -198,7 +198,7 @@ JSON output:
## 🤖 Compatibility with Meilisearch
-This package only guarantees the compatibility with the [version v0.26.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.26.0).
+This package only guarantees the compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0).
## 💡 Learn More
diff --git a/spec/meilisearch/index/search/attributes_to_crop_spec.rb b/spec/meilisearch/index/search/attributes_to_crop_spec.rb
index 1cead71b..153437e7 100644
--- a/spec/meilisearch/index/search/attributes_to_crop_spec.rb
+++ b/spec/meilisearch/index/search/attributes_to_crop_spec.rb
@@ -12,16 +12,51 @@
before { index.add_documents!(document) }
+ it 'searches with default cropping params' do
+ response = index.search('galaxy', attributesToCrop: ['*'], cropLength: 6)
+
+ expect(response.dig('hits', 0, '_formatted', 'description')).to eq('…Guide to the Galaxy is a…')
+ end
+
+ it 'searches with custom crop markers' do
+ response = index.search('galaxy', attributesToCrop: ['*'], cropLength: 6, cropMarker: '(ꈍᴗꈍ)')
+
+ expect(response.dig('hits', 0, '_formatted', 'description')).to eq('(ꈍᴗꈍ)Guide to the Galaxy is a(ꈍᴗꈍ)')
+ end
+
+ it 'searches with mixed highlight and crop config' do
+ response = index.search(
+ 'galaxy',
+ attributesToHighlight: ['*'],
+ attributesToCrop: ['*'],
+ highlightPreTag: ''
+ )
+
+ expect(response.dig('hits', 0, '_formatted', 'description')).to \
+ eq("…Hitchhiker's Guide to the Galaxy is a comedy science…")
+ end
+
+ it 'searches with highlight tags' do
+ response = index.search(
+ 'galaxy',
+ attributesToHighlight: ['*'],
+ highlightPreTag: '',
+ highlightPostTag: ''
+ )
+
+ expect(response.dig('hits', 0, '_formatted', 'description')).to include('Galaxy')
+ end
+
it 'does a custom search with attributes to crop' do
- response = index.search('galaxy', { attributesToCrop: ['description'], cropLength: 15 })
+ response = index.search('galaxy', { attributesToCrop: ['description'], cropLength: 6 })
expect(response['hits'].first).to have_key('_formatted')
- expect(response['hits'].first['_formatted']['description']).to eq('s Guide to the Galaxy is a comedy science')
+ expect(response['hits'].first['_formatted']['description']).to eq('…Guide to the Galaxy is a…')
end
it 'does a placehodler search with attributes to crop' do
- response = index.search('', { attributesToCrop: ['description'], cropLength: 20 })
+ response = index.search('', { attributesToCrop: ['description'], cropLength: 5 })
expect(response['hits'].first).to have_key('_formatted')
expect(response['hits'].first['description']).to eq(document[:description])
- expect(response['hits'].first['_formatted']['description']).to eq("The Hitchhiker\'s Guide")
+ expect(response['hits'].first['_formatted']['description']).to eq("The Hitchhiker\'s Guide to…")
end
end
diff --git a/spec/meilisearch/index/search/multi_params_spec.rb b/spec/meilisearch/index/search/multi_params_spec.rb
index 87b7306a..5a0fd996 100644
--- a/spec/meilisearch/index/search/multi_params_spec.rb
+++ b/spec/meilisearch/index/search/multi_params_spec.rb
@@ -18,7 +18,7 @@
})
expect(response['hits'].count).to be(1)
expect(response['hits'].first).to have_key('_formatted')
- expect(response['hits'].first['_formatted']['title']).to eq('Petit Prince')
+ expect(response['hits'].first['_formatted']['title']).to eq('…Petit Prince')
end
it 'does a custom search with attributesToRetrieve and a limit' do
@@ -94,7 +94,7 @@
expect(response['hits'].count).to be(1)
expect(response['hits'].first).to have_key('_formatted')
- expect(response['hits'].first['_formatted']['title']).to eq('Petit Prince')
+ expect(response['hits'].first['_formatted']['title']).to eq('…Petit Prince')
end
end
end
diff --git a/spec/meilisearch/index/search/nested_fields_spec.rb b/spec/meilisearch/index/search/nested_fields_spec.rb
new file mode 100644
index 00000000..711c4e2d
--- /dev/null
+++ b/spec/meilisearch/index/search/nested_fields_spec.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+RSpec.describe 'MeiliSearch::Index - nested fields search' do
+ include_context 'search books with nested fields'
+
+ it 'searches without params' do
+ response = index.search('an awesome')
+
+ expect(response['hits'].count).to eq(1)
+ expect(response.dig('hits', 0, 'info', 'comment')).to eq('An awesome book')
+ expect(response.dig('hits', 0, 'info', 'reviewNb')).to eq(900)
+ end
+
+ it 'searches within index with searchableAttributes setting' do
+ wait_for_it index.update_searchable_attributes(['title', 'info.comment'])
+ wait_for_it index.add_documents(documents)
+
+ response = index.search('An awesome')
+
+ expect(response['hits'].count).to eq(1)
+ expect(response.dig('hits', 0, 'info', 'comment')).to eq('An awesome book')
+ expect(response.dig('hits', 0, 'info', 'reviewNb')).to eq(900)
+ end
+
+ it 'searches within index with searchableAttributes and sortableAttributes settings' do
+ wait_for_it index.update_searchable_attributes(['title', 'info.comment'])
+ wait_for_it index.update_sortable_attributes(['info.reviewNb'])
+ wait_for_it index.add_documents(documents)
+
+ response = index.search('An awesome')
+
+ expect(response['hits'].count).to eq(1)
+ expect(response.dig('hits', 0, 'info', 'comment')).to eq('An awesome book')
+ expect(response.dig('hits', 0, 'info', 'reviewNb')).to eq(900)
+ end
+end
diff --git a/spec/meilisearch/index/settings_spec.rb b/spec/meilisearch/index/settings_spec.rb
index 76094952..34d4f6c6 100644
--- a/spec/meilisearch/index/settings_spec.rb
+++ b/spec/meilisearch/index/settings_spec.rb
@@ -22,7 +22,8 @@
'stopWords',
'synonyms',
'filterableAttributes',
- 'sortableAttributes'
+ 'sortableAttributes',
+ 'typoTolerance'
]
end
let(:uid) { random_uid }
diff --git a/spec/support/books_contexts.rb b/spec/support/books_contexts.rb
index ae4dd326..fb67a676 100644
--- a/spec/support/books_contexts.rb
+++ b/spec/support/books_contexts.rb
@@ -94,3 +94,68 @@
index.wait_for_task(response['uid'])
end
end
+
+RSpec.shared_context 'search books with nested fields' do
+ let(:index) { client.index('books') }
+ let(:documents) do
+ [
+ {
+ id: 1,
+ title: 'Pride and Prejudice',
+ info: {
+ comment: 'A great book',
+ reviewNb: 50
+ }
+ },
+ {
+ id: 2,
+ title: 'Le Petit Prince',
+ info: {
+ comment: 'A french book',
+ reviewNb: 600
+ }
+ },
+ {
+ id: 3,
+ title: 'Le Rouge et le Noir',
+ info: {
+ comment: 'Another french book',
+ reviewNb: 700
+ }
+ },
+ {
+ id: 4,
+ title: 'Alice In Wonderland',
+ info: {
+ comment: 'A weird book',
+ reviewNb: 800
+ }
+ },
+ {
+ id: 5,
+ title: 'The Hobbit',
+ info: {
+ comment: 'An awesome book',
+ reviewNb: 900
+ }
+ },
+ {
+ id: 6,
+ title: 'Harry Potter and the Half-Blood Prince',
+ info: {
+ comment: 'The best book',
+ reviewNb: 1000
+ }
+ },
+ {
+ id: 7,
+ title: 'The Hitchhiker\'s Guide to the Galaxy'
+ }
+ ]
+ end
+
+ before do
+ response = index.add_documents(documents)
+ index.wait_for_task(response['uid'])
+ end
+end