From 2e1b09e9ef8e36a748de075ced56ba37633fb0a5 Mon Sep 17 00:00:00 2001 From: meili-bot <74670311+meili-bot@users.noreply.github.com> Date: Mon, 11 Apr 2022 15:39:45 +0200 Subject: [PATCH 1/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From ce4ad2147c0fc5c321eefe19745bac0b800cb015 Mon Sep 17 00:00:00 2001 From: meili-bot <74670311+meili-bot@users.noreply.github.com> Date: Tue, 26 Apr 2022 04:40:41 +0200 Subject: [PATCH 2/7] Replace docker command ./meilisearch with meilisearch (#312) * Update .github/workflows/tests.yml * Update .github/workflows/pre-release-tests.yml --- .github/workflows/pre-release-tests.yml | 2 +- .github/workflows/tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 From 39ada4066e6ff44ddced760c3e1851190ec8bcc0 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Tue, 26 Apr 2022 14:17:14 -0300 Subject: [PATCH 3/7] Fix tests according to the v0.27 (#317) * Fix tests according to the v0.27 * Re-run rubocop --auto-gen-config --- .rubocop_todo.yml | 14 +++++++------- .../index/search/attributes_to_crop_spec.rb | 8 ++++---- spec/meilisearch/index/search/multi_params_spec.rb | 4 ++-- spec/meilisearch/index/settings_spec.rb | 3 ++- 4 files changed, 15 insertions(+), 14 deletions(-) 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/spec/meilisearch/index/search/attributes_to_crop_spec.rb b/spec/meilisearch/index/search/attributes_to_crop_spec.rb index 1cead71b..3c3d5e90 100644 --- a/spec/meilisearch/index/search/attributes_to_crop_spec.rb +++ b/spec/meilisearch/index/search/attributes_to_crop_spec.rb @@ -13,15 +13,15 @@ before { index.add_documents!(document) } 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/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 } From e4c0768f516ecb1d9a3e46d1a0078c880d1f9fb6 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Tue, 26 Apr 2022 14:43:09 -0300 Subject: [PATCH 4/7] Add nested fields support (#318) --- .../index/search/nested_fields_spec.rb | 36 ++++++++++ spec/support/books_contexts.rb | 65 +++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 spec/meilisearch/index/search/nested_fields_spec.rb 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/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 From 2a5619289efe916a9f6cc9c870024a518580b378 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Tue, 26 Apr 2022 15:25:36 -0300 Subject: [PATCH 5/7] Add support to the new cropping and highlighting behaviors (#319) --- .../index/search/attributes_to_crop_spec.rb | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/spec/meilisearch/index/search/attributes_to_crop_spec.rb b/spec/meilisearch/index/search/attributes_to_crop_spec.rb index 3c3d5e90..153437e7 100644 --- a/spec/meilisearch/index/search/attributes_to_crop_spec.rb +++ b/spec/meilisearch/index/search/attributes_to_crop_spec.rb @@ -12,6 +12,41 @@ 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: 6 }) expect(response['hits'].first).to have_key('_formatted') From c90b2e850abc4b78895a9b8f3407fb0f02e9d49b Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Sun, 1 May 2022 22:18:55 -0300 Subject: [PATCH 6/7] Add new code-samples related to the v0.27.0 (#321) --- .code-samples.meilisearch.yaml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index c2de6da2..6cfc53e5 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 From 27bb0e96e4a9bef79ba1a1d0d6d726161422fc46 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Thu, 5 May 2022 14:42:48 -0300 Subject: [PATCH 7/7] Update highlight code sample to use single quotes --- .code-samples.meilisearch.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 6cfc53e5..c87dc472 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -239,7 +239,7 @@ search_parameter_guide_highlight_tag_1: |- client.index('movies').search('winter feast', { attributes_to_highlight: ['overview'], highlight_pre_tag: '', - highlight_post_tag: "" + highlight_post_tag: '' }) search_parameter_guide_matches_1: |- client.index('movies').search('winter feast', {